istimeto
发贴: 8
积分: 0
|
于 2008-06-17 00:17
答案应该是:8 public class game { int num[]; int length; int steplength; int currentnum; game(int n[],int len,int steplen) {num=n; length=len; steplength=steplen; currentnum=0; }
public void del(int curnum) { int des; if(curnum+steplength<=length) { des=curnum+steplength-1; System.out.println("des:"); System.out.println(des); } else { des=(steplength-(length-curnum)-1)%(length); }
for(int i=des+1;i<length;i++) { num[i-1]=num[i]; } length--; currentnum=des%length;
} void print() { for(int i=0;i<length;i++) System.out.println(num[i]); System.out.println(","); }
public static void main(String s[]) { int nn[]={1,2,3,4,5,6,7,8,9}; int step=5; game g=new game(nn,nn.length,step); while(g.length>1) {
g.del(g.currentnum); g.print(); } System.out.println(g.num[0]); }
}
|