本文主要是介绍rqn 137 找试场(模拟),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目连接:http://www.rqnoj.cn/Problem_137.html
解题思路:模拟,水题一道,看代码。
#include <stdio.h>
#include <string.h>
const int N = 10;
const int r[] = {1, 2, 3, 0};
const int l[] = {3, 0, 1, 2};int n;
char order[N];int main() {while (scanf("%d", &n) == 1) {int x = 0, y = 0, dir = 0, flag = 0;for (int i = 0; i < n; i++) {scanf("%s", order);if (strcmp(order, "left") == 0)dir = l[dir];else if (strcmp(order, "right") == 0)dir = r[dir];else {int step;flag = 1;sscanf(order, "%d", &step);if (dir == 0)y += step;else if (dir == 1)x += step;else if (dir == 2)y -= step;else if (dir == 3)x -= step;printf("(%d,%d)\n", x, y);}}if (flag == 0)printf("(0,0)\n");}return 0;
}
这篇关于rqn 137 找试场(模拟)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!