MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / solve

Function solve

Spoj_problems/NSTEPS/solution.cpp:9–23  ·  view source on GitHub ↗

Here, in this method, we will solve this problem using a odd and even pattern. And, we will check if the given x,y points lies on line x=y or x-y=2 */

Source from the content-addressed store, hash-verified

7 And, we will check if the given x,y points lies on line x=y or x-y=2
8*/
9int solve(int x, int y){
10 if(x-y==0 && y%2==0){ //line is x=y and even pattern
11 return y*2;
12 }
13 else if(x-y ==0 && y%2 !=0 ){ //line is x=y and odd pattern
14 return (y-1)*2 + 1;
15 }
16 else if(x-y == 2 && y%2 != 0){ //line is x-y=2 and odd pattern
17 return y*2 + 1;
18 }
19 else if(x-y == 2 && y%2 == 0){ //line is x-y=2 and even pattern
20 return y*2 + 2;
21 }
22 else return -1; //no point is there
23}
24int main()
25{
26 jaadu;

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected