Topic links
Https://icpcarchive.ecs.baylor.edu/external/68/6802.pdf
The label of the figure and the two-dimensional array is not quite the same, turn clockwise 90 degrees more comfortable
#include <iostream> #include <cstring>using namespace Std;int vis[100][100];int start_x, Start_y;int Final_ X, final_y;int dirx[4] = {-1, 0, 1, 0}; up or down int diry[4] = {0,-1, 0, 1};char op[300];int face; 0123 North Southwest East int N;int main () {int casen;cin >> casen;for (int cas = 1; CAs <= casen; cas++) {cin >> start_x ;> start_y;cin >> op;memset (Vis, 0, sizeof (VIS)), int x = Start_x;int y = start_y;vis[x][y] = 1;face = 3;n = 0;for (int i = 0; op[i]; i++) {switch (Op[i]) {case ' F ': {switch (face) {case 0:x = x + dirx[0]; y = y + diry[0]; vis[x][y]++; break;case 1:x = x + dirx[1] ; y = y + diry[1]; vis[x][y]++; Break;case 2:x = x + dirx[2]; y = y + diry[2]; vis[x][y]++; Break;case 3:x = x + dirx[3]; y = y + diry[3]; vis[x][y]++; break;} Break }case ' R ': face = (face + 3)% 4; Break;case ' L ': face = (face + 1)% 4; Break;}} final_x = x;final_y = y;for (int i = 0; i <; i++) for (int j = 0; J < + j + +) {if (vis[i][j]>1) n++;} cout << "Case #" << CAS << ":"; cout << final_x << "<< final_y <<" "<< n << endl;}}
UVALive-6802 Turtle Graphics