6 条题解
-
2
代码如下(带题解):
#include <iostream> using namespace std; int main()//头文件 { int n,c=0;//定义 bool a;//用来存储布尔值,详看L4-5 cin >> n;//输入 for (int i=1;i<=n;i++) { a=i/10000==5 or i%10000/1000==5 or i%1000/100==5 or i%100/10==5 or i%10==5;//满足一个条件a的值就是True了 if (i%5==0 && a)//Ture=真的 { c++;//数量增加1 } } cout << c;//输出最终的数量 return 0;//好习惯!(结束) }
给个赞吧!
-
2
#include <iostream> using namespace std; bool huan1(int n) { bool x=false; if (n%5==0) { x=true; } return x; } bool huan2(int n) { bool x=false; while (n>0) { if (n%10==5) { x=true; } n/=10; } return x; } int main() { int n, a=0; cin>>n; for (int i=5;i<=n;i++) if (huan1(i)&&huan2(i)) a++; cout<<a; return 0; }
-
1
这一道题说实话挺简单的,不就是数位拆分吗,我一个刚学到Level4的都会做~
已AC,请放心食用
#include <iostream> using namespace std; int main() { int n, x, o, sum = 0; cin >> n; for (int i = 1; i <= n; i++) { o = 0; x = i; while (x > 0) { if (x % 10 == 5) { o = 1; } x /= 10; } if (i % 5 == 0 && o == 1) { sum += 1; } } cout << sum; return 0; }
- 养成好习惯,看后点个赞( •̀ ω •́ )✧!
- 1
信息
- ID
- 58
- 时间
- 1000ms
- 内存
- 16MiB
- 难度
- 3
- 标签
- 递交数
- 224
- 已通过
- 126
- 上传者