问题:N个人围成一圈,从第一个人开始报数,数到M的人出圈;再由下一个人重新开始报数,数到M的人出圈;…输出依次出圈的人的编号。N,M由键盘输入。
#include <iostream>
using namespace std;
bool a[101]
int main()
{
int m, n;
cin >> n >> m;
cout << endl;
for (int i = 1; i <=n; i++)
a[i] = false;
int f = 0, t = 0, s = 0;
do {
++t;
if (t == n + 1)
t = 1;
if (a[t] == false)
++s;
if (s == m)
{
s = 0;
cout << t << " ";
a[t] == true;
++f;
}
} while (f != 0);
return 0;
}
// Q839540.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
using namespace std;
bool a[101];
int main()
{
int m, n;
cin >> n >> m;
cout << endl;
for (int i = 1; i <= n; i++)
a[i] = false;
int f = n, t = 0, s = 0;
do {
++t;
if (t == n + 1)
t = 1;
if (a[t] == false)
++s;
if (s == m)
{
s = 0;
cout << t << " ";
a[t] = true;
--f;
}
} while (f != 1);
return 0;
}
8 5
5 2 8 7 1 4 6