1
我有一個python腳本,我提供所有輸入一次,然後打印一些輸出。現在,我希望是這種格式python腳本暫停,如何禁用它?
input 1
input 2
input 3
output 1
output 2
我現在的問題是,當我運行python腳本,並打印「輸出1」後,提供輸入(終端粘貼)的輸出停頓和我按Enter鍵再次打印。
from sets import Set
test_cases = int(raw_input())
while test_cases > 0:
cats_vs_dogs = {}
input_ = raw_input()
input_ = input_.split(" ")
total_cats = input_[0]
total_dogs = input_[1]
votes = int(input_[2])
remove_count = 0
cats = Set()
dogs = Set()
for i in range(1, int(total_cats) + 1):
cats.add('C' + str(i))
for i in range(1, int(total_dogs) + 1):
dogs.add('D' + str(i))
for i in range(0, votes):
input_ = raw_input()
input_ = input_.split(" ")
cat = input_[0]
dog = input_[1]
if cat in cats:
cats.remove(cat)
elif cat in dogs:
dogs.remove(cat)
if dog in cats:
cats.remove(dog)
elif dog in dogs:
dogs.remove(dog)
if dog not in cats_vs_dogs:
# now simply add the vote
if cat in cats_vs_dogs:
temp = list(cats_vs_dogs[cat])
temp.append(dog)
cats_vs_dogs[cat] = temp
else:
# cat was not found
cats_vs_dogs[cat] = list([dog])
else:
# relevant dog is present, remove corresponding cat
dogs_list = list(cats_vs_dogs[dog])
if cat in dogs_list:
# remove this entry and don't save it
dogs_list.remove(cat)
cats_vs_dogs[dog] = dogs_list
remove_count += 1
else:
# no reverse entry exists so simply add
if cat not in cats:
cats_vs_dogs[cat] = list([dog])
else:
cats_list = list(cats_vs_dogs[cat])
cats_list.append(dog)
cats_vs_dogs[cat] = cats_list
# now update the count
for k in cats_vs_dogs.keys():
remove_count += len(cats_vs_dogs[k])
print remove_count + len(cats) + len(dogs)
# print 'cats: ', cats
# print 'dogs: ', dogs
test_cases -= 1
cats.clear()
dogs.clear()
cats_vs_dogs.clear()
i電源作爲輸入的是:
2
1 1 2
C1 D1
D1 C1
1 2 4
C1 D1
C1 D1
C1 D2
D2 C1
輸出,我得到的是:
...
D2 C11
<system pause> I press enter
3
,而我想這是因爲
D2 C1<last line>
1
3