第一题:
#include <iostream> using namespace std; int main(){ int T; cin >> T; for(int t = 0; t < T; t++){ cout << "Case #" << t+1 << ":" << endl; int n, m; cin >> n >> m; int direction = 0; int cur_x = 0, cur_y = 0; for(int i = 0; i < m; i++){ char op; int step; cin >> op; if(op == 'L'){ direction = (direction + 3) % 4; } if(op == 'R'){ direction = (direction + 1) % 4; } if(op == 'G'){ cin >> step; if(direction == 0){ cur_y = cur_y - step >= 0? cur_y - step:0; } if(direction == 1){ cur_x = cur_x + step <= n - 1? cur_x + step: n - 1; } if(direction == 2){ cur_y = cur_y + step <= n - 1? cur_y + step: n - 1; } if(direction == 3){ cur_x = cur_x - step >= 0? cur_x-step:0; } } if(op == 'P'){ cout << cur_x << " " << cur_y << endl; } } } return 0; }
AC
第二题:
没记录
没记录
第三题:
没记录
第四题:
没记录
全部评论
(0) 回帖