public class KillMan { /** * @param args */ public static void main(String[] args) { int liveNum=new KillMan().liveNum(17); System.out.println("此人原来是"+liveNum+"号"); }
public class Count3Quit { 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;
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)+"号");}
}