解题思路:比较简单的一道题
注意事项:注意方向的对应,行数是越向下越大
参考代码:
#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 人评分
C语言训练-数字母 (C语言代码)浏览:649 |
WU-链表数据求和操作 (C++代码)浏览:1316 |
剪刀石头布 (C语言代码)浏览:753 |
关于C语言变量位置的问题浏览:273 |
简单的a+b (C语言代码)浏览:581 |
C语言程序设计教程(第三版)课后习题10.3 (C语言代码)浏览:509 |
整除问题 (C语言代码)浏览:526 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:722 |
C语言程序设计教程(第三版)课后习题6.4 (C语言代码)浏览:1200 |
C语言训练-百钱百鸡问题 (C语言代码)浏览:635 |