python日记-使用队列写出特殊字数串

 1 __author__ = "yang xin"
 2 from sys import stdin
 3 # 给出一串数字,首先将第一个数删除,紧接着把第二个数放在这串数字的最后
 4 # 再将第三个数删除,然后将下一个数放在这串数字的最后,直到把最后一个数
 5 # 删除,然后将删除的数字连接起来输出
 6 
 7 test=[]
 8 
 9 ###################################
10 # 先写一个处理输入数据
11 while True:
12     line=stdin.readline().strip()
13     if line=="":
14         break
15     item=line.split(' ')
16     item=[int(i) for i in item]
17     test=item
18 ###################################
19 head=0;
20 tail=test.__len__()
21 while head<tail:
22     print(test[head])
23     head+=1
24     if head<=tail-1:#防止列表下边溢出报错
25         test.append(test[head]) 
26     # test[tail]=test[head]
27     tail+=1
28     head+=1

猜你喜欢

转载自www.cnblogs.com/yangdagaoge/p/9291856.html
今日推荐