You are on page 1of 2

#include <cmath>

#include <iostream>

#include <string>

using namespace std;

int move(string moves){

int x=0,y=0;

for (unsigned int i =0; i<moves.size();i++){

if (moves[i]=='U')

y +=(int(moves[i+1])-48);

if (moves[i]=='D')

y -=(int(moves[i+1])-48);

if (moves[i]=='R')

x +=(int(moves[i+1])-48);

if (moves[i]=='L')

x -=(int(moves[i+1])-48);

int distance = round(sqrt(pow(x,2)+pow(y,2)));

return distance;

bool primality(int n){

if (n==0 || n==1) return false;

for(int i=2; i<=n/2;i++){

if (n%i==0) return false;}

return true;

bool squared(int n){

if (n>=1)

if(sqrt((float)n)==int(sqrt((float)n)))

return true;

return false;

}
int main()

string moves;

int distance;

cin >> moves;

distance=move(moves);

cout << "The distance the vehicle has moved from the origin to the current point is: "<< distance
<< '\n';

int n=distance;

//squared = isSquared(n);

if (primality(n)) {

cout << "Number " << distance << " is prime number\n";

if (squared(n)) {

cout << "Number " << distance << " is square number\n";

return 0;

You might also like