Created
May 26, 2019 10:31
-
-
Save soscler/720ad5e9ccbc94fded1f3b114fb7d70c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> // includes cin to read from stdin and cout to write to stdout | |
using namespace std; // since cin and cout are both in namespace std, this saves some text | |
int main() { | |
int t, n, m, r, c, sr, sc, tr, tc; | |
std::string instruction; | |
cin >> t; // read t. cin knows that t is an int, so it reads it as such. | |
for (int i = 1; i <= t; ++i) { | |
cin >> n >> r >> c >> sr >> sc; // read n and then m. | |
int positions [n+1][c+1] = {0}; | |
positions[sr][sc] = 1; | |
tr = sr; tc = sc; | |
cin >> instruction; | |
for(int i = 0; i< n; i++){ | |
switch (instruction[i]) | |
{ | |
case 'E': | |
while (positions[tr][tc +1] == 1){ | |
tc++; | |
} | |
tc++; | |
break; | |
case 'W': | |
while (positions[tr][tc -1] == 1){ | |
tc--; | |
} | |
tc --; | |
break; | |
case 'N': | |
while (positions[tr -1][tc] == 1){ | |
tr--; | |
} | |
tr--; | |
break; | |
case 'S': | |
while (positions[tr+1][tc] == 1){ | |
tr++; | |
} | |
tr ++; | |
break; | |
default: | |
break; | |
} | |
positions[tr][tc] = 1; | |
} | |
cout << "Case #" << i << ": " << tr << " " << tc << endl; | |
// cout knows that n + m and n * m are ints, and prints them accordingly. | |
// It also knows "Case #", ": ", and " " are strings and that endl ends the line. | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment