KEYENCE Programming Contest 2021 (AtCoder Beginner Contest 227) A

题目:

A - Last Card (atcoder.jp)

此题只需枚举每个数,再根据周期问题,解题。

代码:

#include 
#include 
using namespace std;
#define N 1005
int a[N];
int main(){
    int n,k,f;
    cin >> n >> k >> f;
    a[1] = f;
    for(int i = 2 ; i <= n ; i ++){
        a[i] = (a[i - 1] + 1) % n;
        if (a[i] == 0) a[i] = n;
    }
    int x = k % n;
    if (x == 0) x = n;
    cout << a[x] << endl;
}

你可能感兴趣的:(c,++,c++)