有17个人围成一圈(编号0-16),从第0号的人开始由1报数,凡报到3的倍数的人离开圈子.然后再数下去,直到最后只剩下一个人为止.问此人原来是几号?
解决方案 »
- java中 \n 和 \r 什么区别?(为何在文本框中输入的有回车,而用gettext()取得文本框内容然后写入文件,会发现写不进回车?)
- java参数里,NewSize如果不配置的话,是根据XMS值以及年轻、年老代的默认比率来决定年轻代的大小吗?
- 请问高手关于java3d的问题
- Core Java第二卷有个错误?URLConnectionTest
- showInputDialog上初始一个默认值
- 这是我从网上找的一道题,关于正则表达式方面的,怎么处理?
- 异常程序
- 原码 反码 补码的问题
- 加入我们Boat软件开发团队,让我们一起创业吧!(注意,这不是那些该死的公司招聘广告)
- 未装Jbuilder6前Tomcat运行正常,装后就不正常了.
- 关于创建对象的疑问?高手请进
- 怎样取出List中对象的值?
main()
{
int i,test,p[17],head;
for(i=0;i<16;i++)
p[i]=i+1;
p[16]=0;
test=0;
while(test!=p[test])
{
for(i=1;i<3;i++)
{
head=test;
test=p[test];
}
p[head]=p[test];
test=p[head];
}
printf("\n%5d",test);
解释下
* @param args
*/
public static void main(String[] args) {
int liveNum=new KillMan().liveNum(17);
System.out.println("此人原来是"+liveNum+"号");
}
private int liveNum(int total){
String temp="";
//随便写的,大家不要笑
for(int i=0;i<total;i++){
temp+=""+(char)(i+30000);
}
String tt=temp;
while(temp.length()>2){
temp=temp.substring(3)+temp.substring(0,2);
}
temp=temp.substring(1);
return tt.indexOf(temp);
}}不知以前有人这样写不? 搞笑的.......
public static int peopleCount = 17;
public static void main(String[] args) {
int[] a = new int[peopleCount];
for(int i=0; i<a.length; i++) {
a[i] = 1;
}
int leftCount = peopleCount;
int countNum = 0;
int index = 0;
while(leftCount != 1) {
if(a[index] == 1) {
countNum ++;
if(countNum == 3) {
countNum = 0;
a[index] = 0;
leftCount --;
}
}
index ++;
if(index == a.length) {
index = 0;
}
}
for(int i=0; i<a.length; i++) {
if(a[i] == 1) {
System.out.println("剩下的人的编号为 : " + i);
}
}
}
}
public class run{
int boy_num=17;
newlist nl=new newlist(boy_num);
int way=3;
public run(){
for(int i=0;i<boy_num;i++){
for(int j=0;j<way;j++){
nl.next();
}
nl.gandiao();
}
}
public static void main(String [] ars){
new run();
}
}
class newlist{
int[] boys;
int num;
int location;
public newlist(int a){
location=-1;//因为如果是0的话数的第一为就是1了 为了数的第一位是0所以这里location初始为-1
num=a;
boys=new int[num];
for(int i=0;i<num;i++)
boys[i]=1;
}
public void next(){
if(location==(boys.length-1)){
location=0;
if(boys[location]==0){
next();
}
}else {location++;
if(boys[location]==0){
next();
}
}
}
public void gandiao(){
boys[location]=0;
System.out.println("我挂了,我市"+(location+1)+"号");}
}