私はpythonで初めてです。ここでは、030とr!= 0の場合、Pythonコードの出力
以外のすべての入力に対してうまく動作する、賢明なPythonコードがあります。
私はテストケース(tc)、rとcの数を条件として必要な出力を与える入力として持っています。
質問---入力r = 4の場合& c = 0の場合、出力は2になりますが、出力は1になります。私はすべてのr!= 0 & c = 0の間違った答えを得ています。
コード:
tc=int(input())
while tc:
r,c=raw_input().split()
if int(r)%2==0 and r!=2 and r!=0 and c!=0:
r=int(r)/2
elif r!=2 and r!=0 and c!=0:
r=int(r)/2+1
elif r==0 or r ==2:
r=1
if r!=0:
if int(c)!=0:
print(int(r)*int(c))
else :
if int(r)%2==0 :
print(int(r)/2)
else:
r=int(r)/2+1
print(r)
else :
print(c);
tc=tc-1
サンプル入力及び(種類の)あなたは謎を自分で解決した出力
4 //tc
10 10 //r=10 c= 10
50 //fine
3 3 //r=3 c=3
6 //fine
4 0 //r=4 c=0
1 //Should be 2 accoring to code
5 0 //r=5 c=0
2 //Output should be 3 accoring to the code
実行するコードは何ですか? – Kimvais
インデントを修正してください。 'while'ループがどこで終了するかはわかりません。 –