本文最后更新于 1220 天前,其中的信息可能已经有所发展或是发生改变。
这个题目乍一看比较简单,只需要判断数字的是否包含4或者7即可,但是通过对题目的进一步分析可以发现,这个题目不仅需要判断字符串输入中有无4或7,也需要判断字符串的长度中有无4或7才能解决问题。所以我们进行两个循环,分别判断数字中4和7的个数,以及4和7总和的数字中有无4或7即可。
|
INPUT_VALUE = str(input()) NUM = 0 flag = True for i in INPUT_VALUE: if i is '4' or i is '7': NUM += 1 for i in str(NUM): if i is not '4' and i is not '7': flag = False break if flag: print('YES') else: print('NO') |
代码已经通过codeforces自动检测。
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number n is a nearly lucky number.
Input
The only line contains an integer n (1 ≤ n ≤ 1018).
Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Output
Print on the single line “YES” if n is a nearly lucky number. Otherwise, print “NO” (without the quotes).