依图8.28笔试

第一题:
#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
第二题:
没记录
第三题:
没记录
第四题:
没记录
#笔试题型#
全部评论

相关推荐

凉风落木楚山秋:哈工爷200也去吗
点赞 评论 收藏
分享
06-17 21:57
门头沟学院 Java
白友:噗嗤,我发现有些人事就爱发这些,明明已读不回就行了,就是要恶心人
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务