#include<bits/stdc++.h>
#include<string>
#include<sstream>
using namespace std;
bool rec(int i,int j, int x, int y, int p, int str[])
{
if(i==x && j==y)
{
str[0] = p;
return true;
}
if(x>0 && (i>x||i<(x*-1)))
return false;
if(x<0 && (i<x||i>(x*-1)))
return false;
if(y>0 && (j>y||j<(y*-1)))
return false;
if(y<0 && (j<y||j>(y*-1)))
return false;
int j_len = pow(2,p);
p++;
if(rec(i+j_len, j, x, y, p, str))
{
// cout<<'E';
str[p] = 'E';
return true;
}
if(rec(i, j+j_len, x, y, p, str))
{
// cout<<'N';
str[p] = 'N';
return true;
}
if(rec(i-j_len, j, x, y, p, str))
{
// cout<<'W';
str[p] = 'W';
return true;
}
if(rec(i, j-j_len, x, y, p, str))
{
// cout<<'S';
str[p] = 'S';
return true;
}
return false;
}
void solve()
{
int x,y;
cin>>x>>y;
int str[1000000000] = {0};
if(rec(0,0,x,y,0,str)==false)
{
cout<<"IMPOSSIBLE"<<endl;
return;
}
for(int i=1;str[i] != 0;i++)
printf("%c",str[i]);
cout<<endl;
}
main()
{
int t_case;
cin>>t_case;
for(int i=0;i<t_case;i++)
{
cout<<"Case #"<<i+1<<": ";
solve();
}
}
Usually Codes written on c++14 works on C++17 compiler but not always and I can't understand the difference. Can someone help.
I tried searching online but that didn't helped much.
Also Can someone who regularly Code or is a professional coder can tell me that does my code looks good and written nicely or its messy.
Code's purpose is to give a string as output consisting N,S,E,W representing four directions. a person can jump 2^(the number of jump starting from 0). (Our starting position is 0,0). Suppose the inputs are 2,3 than Output will be SEN .