110A题目网址
题目解析
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==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
;
}