小编ani*_*nil的帖子

Python代码的输出

我是python的新手.这是我的wiered python代码,适用于所有输入,除了

当c = 0且r!= 0时.

我有多个测试用例(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
Run Code Online (Sandbox Code Playgroud)

样本输入和输出

4         //tc
10 10     //r=10 c= 10
50        //fine
3 3       //r=3 c=3
6         //fine
4 0        //r=4 c=0 …
Run Code Online (Sandbox Code Playgroud)

python input python-3.x

-1
推荐指数
1
解决办法
381
查看次数

标签 统计

input ×1

python ×1

python-3.x ×1