We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Number Line Jumps
Number Line Jumps
+ 0 comments string kangaroo(int x1, int v1, int x2, int v2) { for (int i=1; i <= 10000 ; i ++) { if ( x1 == x2 ){ return "YES"; } x1 = x1 + v1; x2 = x2 + v2; } return "NO"; }
+ 0 comments string kangaroo(int x1, int v1, int x2, int v2) { int i = 1; do { x1 = x1 + v1; x2 = x2 + v2; if(x1 == x2) return "YES"; i++; }while (i <= 10000); return "NO"; }
+ 0 comments include
using namespace std;
int main() { int x1, x2, v1, v2;
// Input the values cin >> x1 >> v1 >> x2 >> v2; // Check if the conditions for "YES" are met if (v1 > v2 && (x2 - x1) % (v1 - v2) == 0) { cout << "YES"; } // If none of the conditions are met, print "NO" else { cout << "NO"; } return 0;
}
+ 0 comments Javascript
function kangaroo(x1, v1, x2, v2) { const division = (x2-x1) / (v1-v2) const reminder = (x2-x1) % (v1-v2) return division > 0 && reminder ==0 ? "YES" : "NO" }
+ 0 comments if((x2>x1 )& (v2>=v1)) return "NO"; else if (((x2-x1)%(v1-v2)==0)&&((x2-x1)/(v1-v2)>0)) return "YES"; else return "NO";
Load more conversations
Sort 3631 Discussions, By:
Please Login in order to post a comment