You are viewing a single comment's thread. Return to all comments →
string kangaroo(int x1, int v1, int x2, int v2) { string s; int max=0; int a=x1*v2; int b=x2*v1; if(a>b){ max=a; } else{ max=b; } if(x1==x2){ s="YES"; } else if(x2>x1 && v2>v1){ s="NO"; } else{ for(int i=0; i<=max; i++){ int distance1=((v1*i)+x1); int distance2=((v2*i)+x2); if(distance1==distance2){ s="YES"; return s; } } s="NO"; } return s; }
Seems like cookies are disabled on this browser, please enable them to open this website
Number Line Jumps
You are viewing a single comment's thread. Return to all comments →
c++ solution