2 条题解
-
0
判断能否被3,5,7,整除,用if语句进行判断即可,发现可以被整除后要加标记,定义int类型
b==0,可以整除就b++,最后判断b是否为0,如果是0则为没有,就要输出n。 代码如下using namespace std; int main () { long long int a,b=0;\\b用于做标记 cin>>a; if(a%3==0)\\判断能否被3整除 { cout<<3<<' '; b++;\\加标记 } if(a%5==0)\\判断能否被5整除 { cout<<5<<' '; b++;\\加标记 } if(a%7==0)\\判断能否被7整除 { cout<<7; b++;\\加标记 } if(b==0)\\如果为0,就要输出n。 { cout<<"n"; } return 0;\\结束 } -
-2
#include<bits/stdc++.h> using namespace std; int main() { int a,b,c,d,e,f,g,h; cin>>a; b=a%3==0; c=a%5==0; d=a%7==0; e=b && c; f=c && d; g=b && d; h=b && c && d; if(h) { cout<<"3 5 7"; } else if(e) { cout<<"3 5"; } else if(f) { cout<<"5 7"; } else if(g) { cout<<"3 7"; } else if(b) { cout<<"3"; } else if(c) { cout<<"5"; } else if(d) { cout<<"7"; } else { cout<<'n'; } return 0; }
- 1
信息
- 编号
- 2309
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 2
- 标签
- 递交数
- 100
- 已通过
- 54
- 上传者