Josephus问题
以下是我用C++编写的 Josephus 问题的一个程序,怎么显不出结果来??
#include <iostream.h>
#define ture 1
int main(int argc, char* argv[])
{
const int num=10;
int interval;
int ch[num];
int place=-1;
int count=0;
for(int a=0;a<num;a++)
ch[a]=a+1;
for(int b=0;b<num;b++)
cout<<ch[b]<<" ";
cout<<endl;
cout<<"input number"<<endl;
cin>>interval;
if(interval<0&&interval>10)
{
cout<<"bed number"<<endl;
}
while(ture)
{
for(int a=0;a<interval;)
{
place=(place+1)%num;
if(ch[place]!=0)
a++;
}
cout<<ch[place]<<" ";
if(count==num)
{
cout<<endl;
cout<<"winner:"<<ch[place];
break;
}
ch[place]=0;
count++;
}
return 0;
}