[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;
}

猜你喜欢

转载自www.cnblogs.com/youpeng/p/10720233.html
0条评论
添加一条新回复