您的位置:首页 > 其它

50个人围成一圈数到3和3的倍数时出圈,问剩下的人是谁?在原来的位置是多少

2015-03-02 23:11 288 查看
public class T1{

public T1() {
// TODO Auto-generated constructor stub
}

public static void main(String[] args) {
// TODO Auto-generated method stub

int peoplenum =50 ;
boolean[] p = new boolean[peoplenum];

int num = 1;
int count = 0;
for(int i=0;i<50;i++){
p[i]=true;
}

while(peoplenum>1 ){

if(count==50){
count=0;
}

if( p[count]==true ){
if(num %3 ==0 ){
p[count]=false;
peoplenum--;

}
num++;
}

count++;

} //end while

for(int i=0;i<50;i++){
if(p[i]==true){
System.out.println(i+1);
}
}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐