关于Codechef

时间:2018-05-14 03:18:19

标签: python python-3.x

我正在处理问题link

代码:

lenInput= int(input())
 while lenInput:
   temCnt=0
   proInput = str(input())
   lenCnt= len(proInput)
   for i in range (lenCnt):
     if (proInput[i] == '4') or (proInput[i] =='7'):
       temCnt+=1
   print(lenCnt -temCnt)
   lenInput-=1 

我能够为网站中提到的用例获取正确的输出,但是在提交我的代码时。 它会抛出错误"错误答案"

你能帮我理解,为什么会抛出错误?

1 个答案:

答案 0 :(得分:1)

为什么你str(input())input()已经为您提供了一个字符串。

这里唯一需要做的就是将任何非幸运数字改为幸运数字。所需的更改量是非幸运数字的数量:

for _ in range(int(input())):    # loop over each test case
    i = 0                          # start counting at 0
    for c in input():              # loop over each character of input testcase
        if c not in ['4','7']:     # if character not lucky, count it
            i+=1
    print(i)                     # print count
相关问题