【摘要】 110A题目网址
题目解析
1.输入一个数字,如果数字中包含的4,7的数量是4或7的倍数,则输出YES,否则输出NO 举例: 输入: 40047 输出: NO
2.注意点: 1)由于数字很长,所以使用long long int类型,使用scanf(“%lld”,&n)接收输入
2)整型转字符串,使用sprintf(字符串,“lld”,整型);,如:sprintf…
题目解析
1.输入一个数字,如果数字中包含的4,7的数量是4或7的倍数,则输出YES,否则输出NO
举例:
输入:
40047
输出:
NO
2.注意点:
1)由于数字很长,所以使用long long int类型,使用scanf(“%lld”,&n)接收输入
2)整型转字符串,使用sprintf(字符串,“lld”,整型);,如:sprintf(s,”%lld”,n);
3)因为幸运数字可能会比较多,所以count%10==4或7去判断
4)使用整型转字符串,就使用sprintf(),其他的转换有问题.
代码
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main()
{
long long int n;
int count=0;
scanf("%lld",&n);
char s[30]={'\0'};
sprintf(s,"%lld",n);
for(int i=0;i<strlen(s);i++)
{
if(s[i]=='4'||s[i]=='7')
{ count++;
}
} if(count==0)
{
printf("NO");
}else if(count>0){
if(count%10==4||count%10==7)
{ printf("YES");
}else
{ printf("NO");
} }
system("pause");
return 0;
}
文章来源: blog.csdn.net,作者:DQ_CODING,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/qq_45402917/article/details/116836871
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END