MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / main

Function main

CPP/char array/shortespath.cpp:9–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7#define endl '\n'
8
9int main(){
10 cin.tie(0)->sync_with_stdio(0);
11 char s[1000];
12 cin.getline(s,1000);
13 int x,y;
14 x=0;
15 y=0;
16 for (int i = 0; s[i] !='\0'; i++) {
17 switch(s[i]){
18 case 'N':
19 y++;
20 break;
21 case 'S':
22 y--;
23 break;
24 case 'E':
25 x++;
26 break;
27 case 'W':
28 x--;
29 break;
30 }
31
32
33 }
34 cout<<"the value of x and y is:"<<x<<" "<<y<<endl;
35 if(x>=0 && y>=0){
36 while(x--){cout<<"E";}
37 while(y--){cout<<"N";
38 }
39 }
40 else if(x<=0 && y>=0){
41 while(x--){cout<<"W";}
42 while(y--){cout<<"N";}
43 }
44 else if(x<=0 && y<=0){
45 while(x--){cout<<"W";}
46 while(y--){cout<<"S";}
47 }
48 else
49 {
50 while(x--){cout<<"E";}
51 while(y--){cout<<"S";}
52 }
53
54 return 0;
55}
56

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected