Description
定义幸运数字为每一位都是4或7的数字,现在给出一个数字 n ,问其4或7的数量是否是幸运数字
Input
一个正整数
Output
如果 n <script type="math/tex" id="MathJax-Element-33">n</script>中4或7的数量是否是幸运数字则输出YES,否则输出NO
Sample Input
40047
Sample Output
NO
Solution
水题,统计4或7的数量判断一下即可
Code
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=100001;
char s[maxn];
int check(int n)
{
if(n==0)return 0;
while(n)
{
if(n%10!=4&&n%10!=7)return 0;
n/=10;
}
return 1;
}
int main()
{
while(~scanf("%s",s))
{
int n=strlen(s),num=0;
for(int i=0;i<n;i++)
if(s[i]=='4'||s[i]=='7')num++;
if(check(num))printf("YES\n");
else printf("NO\n");
}
return 0;
}