65 条题解
-
0
#include <iostream> using namespace std; int main() { int n; cin >> n; if (n == 1) { cout << "swim" << endl; } else if (n == 3) { cout << "program" << endl; } else if (n == 5) { cout << "read" << endl; } else if (n == 6) { cout << "math" << endl; } else { cout << "rest" << endl; } return 0; }
-
0
#include <iostream> //当然可以用万能头 using namespace std; int main() { int n; cin >> n; if (n == 1) { cout << "swim"; } if (n == 3) { cout << "program"; } if (n == 5) { cout << "read"; } if (n == 6) { cout << "math"; } if (n == 2 or n == 4 or n == 7) //逝逝用else😕 { cout << "rest"; } return 0; }
-
0
这道题如果所有的判断都是
if
那么当你输入1时,你会得到一个大大的swimrest
,但如果我们在之后的3个if
千加上else
它就变成了else if
这样这道题就对了代码如下:#include<bits/stdc++.h> using namespace std; int main(){ int n;cin>>n; if(n==1){ cout<<"swim"; } else if(n==3){ cout<<"program"; } else if(n==5){ cout<<"read"; } else if(n==6){ cout<<"math"; }else{ cout<<"rest"; } return 0; }
编码不易,点个赞吧😄
-
0
全网最笨方法
//hetao29146用户 #include <iostream> using namespace std; int main() { int a; cin>>a; if (a==1) //判断是否是星期一 cout<<"swim"<<endl; else if (a==3) //判断是否是星期三 cout<<"program"<<endl; else if (a==5) //判断是否是星期五 cout<<"read"; else if (a==6) //判断是否是星期六 cout<<"math"; else cout<<"rest"; }
-
0
#include <iostream> using namespace std; int main() { int day; cin >> day; switch (day) {//这个语句很高级,作用相当于if判断,可以省去if的麻烦 case 1: cout << "swim" << endl; break; case 3: cout << "program" << endl; break; case 5: cout << "read" << endl; break; case 6: cout << "math" << endl; break; default: cout << "rest" << endl; } return 0; }
-
0
int n; cin >> n; bool a,b,c,d;//不懂了看我上一题的题解 a = (n == 1); b = (n == 3); c = (n == 5); d = (n == 6); if (a)//接下来判断 { cout << "swim"; } else if (b)//else if是“否则 如果(判断)” { cout << "program"; } else if (c) { cout << "read"; } else if (d) { cout << "math"; } else { cout << "rest"; }
</span>
这题也能用布尔!
点赞!!!
(此代码来之不易,是原创,先点赞吧!)
-
0
#include <bits/stdc++.h> using namespace std; int main() { int n;//定义 cin >> n;//输入 if (n==1)//周一 { cout << "swim"; } else if (n==3)//周三 { cout << "program"; } else if (n==5)//周五 { cout << "read"; } else if (n==6)//周六 { cout << "math"; } else//其他时候 { cout << "rest"; } return 0; }
-
0
这道题一如既往的简单,
我的方法也简单粗暴。
只要你不怕累,就可以定义一个string数组a,
然后赋值......
话不多说,上代码!#include<iostream> #include<string> using namespace std; string a[8]; int main() { for (i = 1; i <= 7; i++) { a[i] = "rest"; } a[1] = "swim"; a[3] = "program"; a[5] = "read"; a[6] = "math"; //换成 a = {"e", "swim", "rest", "program", "rest", "read", "math", "rest"}也可以; int b; cin >> b; cout << a[b] << endl; re turn 0; }
小盆友们,您学会了吗?
复制?
代码不易,先点赞,再复制吧!
(不要忘了删倒数第二行的空格!) -
0
#include <bits/stdc++.h>//惯用万能头,万事皆从头。(笑) using namespace std; int main() { long long n;//long long一在,谁都不爱;long long出征,寸草不生。 cin >> n; if(n == 1)//用if,else if,else判断,来确定输出。 { cout << "swim"; } else if(n == 3) { cout << "program"; } else if(n == 5) { cout << "read"; } else if(n == 6) { cout << "math"; } else//这里如果用else,不会出错,因为用的是if,else if,else; { cout << "rest"; } return 0; }
信息
- ID
- 666
- 时间
- 1000ms
- 内存
- 64MiB
- 难度
- 4
- 标签
- 递交数
- 8405
- 已通过
- 3903
- 上传者