解题思路:比较简单的一道题
注意事项:注意方向的对应,行数是越向下越大
参考代码:
#include <iostream> #include <vector> #include <string> using namespace std; char dir; int x, y, step; void rotate(bool right) { if(right) { if (dir == 'U') dir = 'R'; else if (dir == 'R') dir = 'D'; else if (dir == 'D') dir = 'L'; else dir = 'U'; } else { if (dir == 'U') dir = 'L'; else if (dir == 'R') dir = 'U'; else if (dir == 'D') dir = 'R'; else dir = 'D'; } } void forward(char dir) { if (dir == 'U') --x; else if (dir == 'R') ++y; else if (dir == 'D') ++x; else --y; } int main() { int m, n; cin >> m >> n; int temp; vector<vector<int>> mat = vector<vector<int>>(m, vector<int>(n)); for(int i = 0; i < m; ++i) { for(int j = 0; j < n; ++j) { cin >> temp; mat[i][j] = temp; } } cin >> x >> y >> dir >> step; // cout << dir << " " << x << " " << y << endl; for(int i = 0; i < step; ++i) { if(mat[x][y] == 0) { rotate(false); mat[x][y] = 1; forward(dir); } else { rotate(true); mat[x][y] = 0; forward(dir); } // cout << dir << " " << x << " " << y << endl; } cout << x << " " << y; }
0.0分
0 人评分
A+B for Input-Output Practice (V) (C语言代码)浏览:625 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:842 |
愚蠢的摄影师 (C++代码)浏览:938 |
简单的a+b (C语言代码)浏览:419 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:1072 |
DNA (C语言代码)浏览:750 |
震宇大神的杀毒软件 (C语言代码)浏览:1080 |
Pascal三角 (C语言代码)浏览:653 |
C语言程序设计教程(第三版)课后习题7.4 (C语言代码)浏览:492 |
C语言程序设计教程(第三版)课后习题8.1 (C语言代码)浏览:568 |