二级阅读程序-1

阅读程序,完成下面的选择或判断

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#include <iostream>
using namespace std;
int main() {
    int n, k, pos;
    cin >> n >> k >> pos;
    int a[1010], b[1010];
    for (int i = 1; i <= n; i++) a[i] = i;
    for (int t = 1; t <= k; t++) {
        for (int j = 1; j <= n; j++) {
            if (j % 2 == 1) b[j] = a[(j + 1) / 2];
            else b[j] = a[n / 2 + j / 2];
        }
        for (int j = 1; j <= n; j++) a[j] = b[j];
}
cout << a[pos] << endl;
return 0;
}
Scroll to Top