标签:数组 remove lis append string range index main 元素
person = []print ‘current person list:%s‘ % person
print ‘current removelist:%s‘ % removelist
print ‘left person list:%s‘ % person
java 版:
import java.util.ArrayList;
import java.util.List;
public class TestShushu {
public static void main(String[] args) {
// TODO Auto-generated method stub
List<Integer> list = new ArrayList<Integer>();
for(int i=1;i<4;i++) {
list.add(i);
}
System.out.println(list);
int index = 0;
while(list.size() > 1) {
List<Integer> removelist = new ArrayList<Integer>();
for(int i: list) {
index ++;
if(index == 3) {
removelist.add(i);
//System.out.println(removelist);
index = 0;
}
}
System.out.println("要删除的数组" + removelist);
list.removeAll(removelist);
System.out.println("当前数组元素:" + list);
}
System.out.println("最后留下的那个编号:" + list);
}
}
python 实现N个人,从1数到3,数到3的出局,来回循环,最后剩下一个人
标签:数组 remove lis append string range index main 元素
原文地址:http://blog.51cto.com/dreamgirl1314/2351212