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%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;
}