[CodeForces - 659A] Round House

题目链接:http://codeforces.com/problemset/problem/659/A

在一个环中是按照升序方向走还是按照降续方向走

AC代码:

#include<cstdio>
#include<algorithm>

using namespace std;

int main() {
    int n, a, b;
    bool flag;
    while (scanf("%d%d%d", &n, &a, &b) != EOF) {
        if(b<0)
            flag = true;
        else
            flag = false;
        b = abs(b);
        int route = b % n;
        if (flag) {
            while (route != 0) {
                a--;
                if (a < 1) {
                    a = n;
                }
                route--;
            }
        }
        else {
            while (route != 0) {
                a++;
                if (a > n)
                    a = 1;
                route--;
            }
        }
        printf("%d\n", a);
    }
    return 0;
}
posted @ 2019-04-16 21:40  Youpeng  阅读(144)  评论(0编辑  收藏  举报