私はそれが非常に基本的な質問であることを知っていますが、私はPython環境の初心者でもあります. 入力テストケースを読む必要がある最初のプログラム(データ構造の問題)を書いています。
入力:
The first line contains the number of test cases T. T test cases follow.
The first line for each case contains N, the number of elements to be sorted.
The next line contains N integers a[1],a[2]...,a[N].
制約:
1 <= T <= 5
1 <= N <= 100000
1 <= a[i] <= 1000000
サンプル入力:
2
5
1 1 1 2 2
5
2 1 3 1 2
if-else
ファイルから上記の入力を読み取るために次のプログラムを作成しましたが、これは最善の方法ではないと確信していfor
ますinputs
。
sample = open('sample.txt')
first = sample.readline()
if len(first) > 5 or len(first) <1:
print "Not correct input";
else:
test = sample.readline
for x in range(0,len(first)):
second = sample.readline()
if len(second) >100000 or len(second) < 1:
print "wrong input";
else:
third = list()
for y in range(0, len(third)):
third.append(sample.readline()[:1])
method_test(third) #calling a method for each sample input
最善の解決策を教えてください。