这是一个创建于 3694 天前的主题,其中的信息可能已经有所发展或是发生改变。
我的思路是:
1.设定一个布尔数组,所有值赋为真
2.设定三个累加器 s、j、b ,s 用来报数,j用来循环、联系头和尾,b用来统计圈内剩余人数
3.出圈的赋为假,输出圈中为真的元素。
代码如下,是按照思路写的,但是有问题,不曾能找的出来。
#include<iostream>
#include<cstdlib>
using namespace std;
int a[100];
int main()
{
int m,n;
cin >>m>>n;
int b;
int s=1;
int i;
int j=1;
b=m;
for(i=1;i<=m;i++)
a[i]=1;
do {
if (a[j]==1)
s++;
if (s==n)
{
a[i]=0;
s=1;
b--;
}
j++;
if (j=n+1)
j=1;
}while(b==1);
for (i=1;i<=m;i++)
if (a[i]==1)
{
cout <<i;
break;
}
system("pause");
return 0;
}
6 条回复 • 2014-09-10 03:26:56 +08:00
|
|
1
sophymax 2014-09-09 21:17:27 +08:00
占前排,坐等楼主被喷
|
|
|
2
paulw54jrn 2014-09-09 21:20:30 +08:00
好歹发个gist..
|
|
|
3
Cee 2014-09-09 21:24:19 +08:00
代碼好亂 中間a[i]=0; 和i有啥關係? 而且判斷時候你的s已經做了s++了,也是要找到下一個人啊
|
|
|
4
Cee 2014-09-09 21:27:10 +08:00
做算法題目前先整理一下思路。
|
|
|
5
msg7086 2014-09-10 03:09:04 +08:00
首先,你需要把变量的名字弄正常;
|
|
|
6
msg7086 2014-09-10 03:26:56 +08:00
|