Files
ClassFeedback/C++代码/CSP04/01/小杨的报数游戏.cpp

32 lines
547 B
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include <iostream>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int arr[110] = {0}; // 0表示当前这个同学还在,1表示这个同学出列了
int idx = 1; // 表示当前这个叫到第几个同学
int cnt = 0; // 本轮报数的计数器
int p = n; // 当前人数
while(p != 0){
// 先判断当前这个人是不是出列了
if(arr[idx] == 0){
cnt++;
if(cnt == k){
// 这个人出列
cout << idx << " "; // 当前这个人出列
arr[idx] = 1; // 修改当前这个人出列状态
p--;
cnt = 0;
}
}
idx++;
if(idx > n){
idx = 1;
}
}
return 0;
}