Codeforces习题 110A Nearly Lucky Number

发布于 / 技术 / 0 条评论

这个题目乍一看比较简单,只需要判断数字的是否包含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 477444 are lucky and 517467 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).

本网站在未特殊说明的情况下采用知识共享署名-非商业性使用-相同方式共享 3.0 协议进行许可。
<-数据丢失->