python实现CCF 201912-1《报数》

python实现CCF 201912-1《报数》_第1张图片

n = int(input())
cout = 0
a = 1
cout1,cout2,cout3,cout4 = 0,0,0,0
while cout<n:
    b = a+1
    c = a+2
    d = a+3
    if a%7 == 0 or ('7' in  str(a)):
        cout1 +=1
    else:
        cout +=1
    if cout >= n:
        break
    if b%7 == 0 or ('7' in  str(b)):
        cout2 +=1
    else:
        cout +=1
    if cout >= n:
        break
    if c%7 == 0 or ('7' in  str(c)):
        cout3 +=1
    else:
        cout +=1
    if cout >= n:
        break
    if d%7 == 0 or ('7' in  str(d)):
        cout4 +=1
    else:
        cout +=1
    if cout >= n:
        break
    a += 4
print(cout1)
print(cout2)
print(cout3)
print(cout4)

本题较简单,只需要一个循环+条件判断即可。这是我做的第一题,花了半小时左右即可完成。

你可能感兴趣的:(CCF,python,算法)