猴子选大王有点问题
import java.io.*;class Hou{
int a[];
Hou(int b)
{ a=new int [b+1];
a[0]=b;
for(int i=1;i<=b;i++)
a[i]=1;
}
int xuanhou(int n){
int i=1,k=0;
while(a[0]>1){
if(a[i]==1){
k++;
if(k==5){
k=0;
a[i]=0;
a[0]--;
}
}
i=i+1;
if(i>n) i=i%n;
}
for(i=1;i<=n;i++)
if(a[i]==1)
return i;
}
}
public class TestHou{
public static void main(String args[])throws IOException
{
String str;
BufferedReader buf;
buf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("input an integer:");
str=buf.readLine();
int n=Integer.parseInt(str);
Hou p=new Hou(n);
//int m=p.xuanhou(n);
System.out.println("最后留下的是"+p.xuanhou(n));
}
}
return i;
这块好象有问题?