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.
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.
Print on the single line "YES" if n is a nearly lucky number. Otherwise, print "NO" (without the quotes).
40047
NO
7747774
YES
1000000000000000000
NO
题意:给出幸运数字的概念是该数字仅含4和7. 然后给出Nearly Lucky Number 的定义:对于一个数n,它每位上4或7的个数如果是幸运数,输出YES,否则输出NO。
#include <iostream>
#include <algorithm> #include <cstring> #include <cstdio> #include <cctype> #include <cstdlib> #include <set> #include <map> #include <vector> #include <string> #include <queue> #include <stack> #include <cmath> using namespace std; const int INF=0x3f3f3f3f; #define LL long long int main() { LL n;char s[22],c[22]; while(cin>>n) { sprintf(s,"%lld",n); int cnt=0; for(int i=0;i<strlen(s);i++) { if(s[i]=='4'||s[i]=='7') cnt++; } sprintf(c,"%d",cnt); int flag=1; for(int i=0;i<strlen(c);i++) { if(c[i]!='4'&&c[i]!='7') { flag=0; break; } } if(flag) puts("YES"); else puts("NO"); } return 0; }