codeforces 110A-C语言解题报告
生活随笔
收集整理的這篇文章主要介紹了
codeforces 110A-C语言解题报告
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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; }總結
以上是生活随笔為你收集整理的codeforces 110A-C语言解题报告的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SpringBoot 集成Nacos报错
- 下一篇: 为什么我喜欢单独编程