65 条题解

  • 69
    @ 2022-7-13 22:27:35

    这道题多用几次if就行了,不过有点麻烦😕

    #include <bits/stdc++.h> 
    using namespace std;
    int main()
    {
        int n;
        cin >> n;
        if(n == 1)//进行4次判断,来确定输出。
        {
            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,会出错,因为会把rest追加到program和read末尾。
        { 
            cout << "rest";
        }
        return 0;
    }
    

    你问我这么简单的题为什么写题解???因为这道题的题号ID太,,,可爱了(bushi

    编码不易😕,点赞走起👀️
    记得点赞再抱走奥😄

    • @ 2022-7-15 16:32:48

      除了main()的大括号,其他大括号都有些多余,不信你去了试试

    • @ 2022-7-15 23:48:06

      @ 哦哦,谢谢提醒

    • @ 2022-7-16 16:47:52

      @ 给下面我的点下赞呗,就是用数组的那个

    • @ 2022-7-24 23:05:51

      最后一个判断or可以写成||

    • @ 2022-8-16 20:18:33

      其实你可以简化一下,可以看看我的呗,顺便点个赞呗~求求了

    • @ 2022-8-26 11:45:18

      对@

    • @ 2022-8-26 11:49:00

      #include <iostream> using namespace std; int main(){ int n; cin>>n; if(n1)cout<<"swim"; if(n3)cout<<"program"; if(n5)cout<<"read"; if(n6)cout<<"math"; if(n2 or n4 or n==7)cout<<"rest"; return 0; }

    • @ 2022-8-29 13:51:21

      if , else if , else

    • @ 2023-7-7 20:34:36

      为何不用switch?

    • @ 2023-8-10 17:53:30

      嘿嘿😁

    • @ 2024-1-28 21:48:56

      最后一个判断里的“or”改成“||”😄

    • @ 2024-1-28 21:49:46

      当中的可以用“else if”😄

  • 23
    @ 2022-7-8 17:35:27
    #include <iostream>//调用
    using namespace std;
    string a[8] = {"rest","swim","rest","program","rest","read","math","rest"} ;
    //定义数组,周n,对应 a[n] ,注意数组下标从0开始
    //也可以string a[7]={"swim","rest"…… 但是后面是cout << a[n-1]
    short int n ;//输入用 因为在1~7中,short int 足矣
    int main(){
    	cin >> n;//输入
    	cout << a[n];//直接输出
    	return 0 ;
    }
    
    #include <iostream>
    using namespace std;
    string a[7] = {"swim","rest","program","rest","read","math","rest"} ;
    //同上,这次直接 a[7]少开一个空间
    int main(){
    	cout << a[getchar() - '1'];//getchar获取一个字符,正好在范围内
    	//char类型 - '0' 是转化数字 , 再减一就是下标(0开始),所以直接 减'1'
    	return 0 ;
    }
    
    • @ 2022-7-11 13:47:25

      定义字符串数组不需要调用string库吗?

    • @ 2022-7-11 21:30:18

      @ <iostream>需要用到std::ios_base类型,std::ios_base有个成员函数 的返回类型是std::locale,std::locale定义在<locale>头文件,<locale>中还有一个叫 做std::numpunct的类模板,std::numpunct有一个成员函数的返回类型是std::string。 查的,所以不需要

    • @ 2023-6-15 17:37:45

      你的代码有错误,根本运行不了,你确定你试过了 ?

    • @ 2024-3-10 20:38:28

      int main()去哪了?

  • 9
    @ 2023-8-9 19:42:55
    #include <iostream>
    using namespace std;
    int main()
    {
        int a;
        string b[7]={"swim","rest","program","rest","read","math","rest"};
        cin>>a;
        cout<<b[a-1];
    }
    
    • 6
      @ 2023-8-17 21:54:16

      不会吧,这么简单 应该都会吧......(先 后看!养成习惯!)

      #include <iostream>
      //       瓦是不会告诉你还有万能头文件这种东西的
      using namespace std;
      int main()
      {
          int a;
          cin>>a;//输入a
          if(a==1)
          {
              cout<<"swim";
              //游泳课输出“swim”
          }
          else if(a==3)//当然else也行
          {
              cout<<"program";
              //编程课输出“program”
          }
          else if(a==5)//当然else也行
          {
              cout<<"read";
              //阅读课输出“read”
          }
          else if(a==6)//当然else也行
          {
              cout<<"math";
              //数学课输出“math”
          }
          else
          {
              cout<<"rest";
              //没课输出“rest”
          }
          return 0;
      }
      

      制作不易,给个赞吧,球球了...... 有什么问题,联系我,邮箱是ASheepBoy_Bed@163.com

      • @ 2023-8-17 21:56:27

        6

      • @ 2024-1-1 16:47:20

        #include <iostream> using namespace std; int main() { cout<<"666" <<" "<<"999"<<" "<<endl; }

    • 4
      @ 2023-9-3 18:59:49
      #include <iostream>
      using namespace std;
      int main()
      {
          int a;
          cin >> a;
          if (a == 1)
          {
              cout << "swim";
          }
          else
          {
              if (a == 3)
              {
                  cout << "program";
              }
              else
              {
                  if (a == 5)
                  {
                      cout << "read";
                  }
                  else
                  {
                      if (a == 6)
                      {
                          cout << "math";
                      }
                      else
                      {
                          cout << "rest";
                      }
                  }
              }
          }
          return 0;
      }
      
      • 2
        @ 2023-8-10 16:54:42
        #include <iostream>
        using namespace std;
        int main()
        {
            int a;
            cin >> a;
            if (a == 1)
            {
                cout << "swim";
            }
            else
            {
                if (a == 3)
                {
                    cout << "program";
                }
                else
                {
                    if (a == 5)
                    {
                        cout << "read";
                    }
                    else
                    {
                        if (a == 6)
                        {
                            cout << "math";
                        }
                        else
                        {
                            cout << "rest";
                        }
                    }
                }
            }
            return 0;
        }
        
      • 2
        @ 2023-8-9 17:03:07
        #include <bits/stdc++.h> 
        using namespace std;
        int main()
        {
            int n;
            cin>>n;
            if (n==1)
            {
                cout<<"swim";
            }
            if (n==2)
            {
                cout<<"rest";
            }
            if (n==3)
            {
                cout<<"program";
            }
            if (n==4)
            {
                cout<<"rest";
            }
            if (n==5)
            {
                cout<<"read";
            }
            if (n==6)
            {
                cout<<"math";
            }
            if (n==7)
            {
                cout<<"rest";
            }
            return 0;
        }
        
      • 1
        @ 2024-5-12 14:55:42

        非常的简单,代码来了!

        #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){
        cout << "rest";//其他时间休息
        }
        return 0;
        }//点个赞吧,谢谢!
        
        • 1
          @ 2024-1-31 14:06:47

          点个赞吧😄

          #include <bits/stdc++.h> 
          using namespace std;
          int main()
          {
              int a;
              cin >> a;
              if (a == 1)//判断是否是游泳课
              {
                  cout << "swim";
              }
              else if (a == 3)//判断是否是编程课
              {
                  cout << "program";
              }
              else if (a == 5)//判断是否是阅读课
              {
                  cout << "read";
              }
              else if (a == 6)//判断是否是数学课
              {
                  cout << "math";
              }
              else//没有课输出"rest"
              {
                  cout << "rest";
              }
              return 0;
          }
          
          • 1
            @ 2024-1-28 21:46:41

            直接上代码😄:

            #include <bits/stdc++.h>
            using namespace std;
            int n;//n代表今天是星期几
            int main()
            {
            cin>>n;//从键盘读入今天是星期几
            if(n==1)//是否是游泳课(周一)
            {
            cout<<"swim";//“swim”
            }
            else if(n==3)//是否是编程课(周三)
            {
            cout<<"program";//输出“program”
            }
            else if(n==5)
            {
            cout<<"read";//输出“read”
            }
            else if(n==6)//是否是阅读课(周五)
            {
            cout<<"math";//输出“math”
            }
            else//如果没课
            {
            cout<<"rest";//输出“rest”
            }
            return 0;
            }
            

            测试可通过😄 : image

            • 1
              @ 2024-1-17 20:59:35
              #include <bits/stdc++.h> 
              using namespace std;
              int main()
              {
                  int n;
                  cin >> n;
                  cout << "swim";
                  return 0;
              }
              
              • @ 2024-1-17 21:20:10

                点个赞吧求求了!(制作不易)

            • 1
              @ 2023-8-28 16:10:08
              ###只要一个很简单的if,else if ,else循环### 
              #include <bits/stdc++.h>//万能开头
              using namespace std;
              int n;//定义变量
              int main()
              {
                  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//其他
                  {
                      cout<<"rest";
                  }
                  return 0;
              }
              //一手交赞,一手交货(代码)
              
              
              
              
              
              
              //核桃hetao1609095编程
              //水印
              
              • 0
                @ 2024-2-16 16:56:23

                额,这题不难,毕竟是L1的题嘛😄 ,话不多说,上代码!!! (AC滴,各位大佬)``` #include <bits/stdc++.h>//你不会不知道万能头文件吧!!!! using namespace std; int main() { int n; cin>>n; if(n1)//是周一 { cout<<"swim";//输出课程 } else if(n3)//是周三 { cout<<"program";//输出课程 } else if(n5)//是周五 { cout<<"read";//输出课程 } else if(n6)//是周六 { cout<<"math";//输出课程 } else//没有课程 { cout<<"rest";//输出结果 } return 0;//结束 }

                
                
                • 0
                  @ 2024-1-3 21:17:57
                  #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)
                      { 
                          cout << "rest";
                      }
                      return 0;
                  }
                  
                  • 0
                    @ 2023-12-30 18:38:59
                    #include <iostream>
                    using namespace std;
                    int main()
                    {
                        int n;
                        cin >> n;
                        //代码有些《简洁》
                        if (n == 2 || n == 4 || n == 7){cout << "rest";return 0;}
                    
                        if (n == 1)
                        {
                            cout << "swim";return 0;
                        }else if (n == 3)
                        {
                            cout << "program";return 0;
                        }else if (n == 5)
                        {
                            cout << "read";return 0;
                        }
                    
                        cout << "math";
                    }
                    
                    • 0
                      @ 2023-11-12 10:41:16
                      #include <bits/stdc++.h> 
                      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)
                          { 
                              cout << "rest";
                          }
                          return 0;
                      }
                      
                      • 0
                        @ 2023-10-1 10:50:34

                        #include <iostream> using namespace std; int main() { int a; cin>>a; if (a == 1) { cout <<"swim"; } else if (a == 3) { cout <<"program"; } else if (a == 5) { cout <<"read"; } else if (a == 6) { cout <<"math"; } else { cout<<"rest"; } return 0; }

                        • 0
                          @ 2023-8-23 0:39:57
                          #include <iostream>
                          #include <cstdio>
                          
                          using namespace std;
                          
                          int main()
                          {
                              int n;
                              scanf("%d", &n);
                          
                              switch(n) /* 直接 switch,嘿嘿~~~{
                                  case 1:
                                      cout << "swim\n";
                                      break;
                                  case 3:
                                      cout << "program\n";
                                      break;
                                  case 5:
                                      cout << "read\n";
                                      break;
                                  case 6:
                                      cout << "math\n";
                                      break;
                                  default:
                                      cout << "rest\n";
                              }
                          
                              return 0;
                          }
                          

                          点赞,嘿嘿~~~

                          • 0
                            @ 2023-8-14 15:24:13

                            #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) { cout << "rest"; } return 0; }

                            • 0
                              @ 2023-8-11 21:35:11
                              #include <iostream>
                              using namespace std;
                              int main()
                              {
                              int a;
                              cin>>a;
                              if (a==1)//判断是否是周一
                              {
                              cout<<"swim";
                              }
                              else if (a==3)//是否是周三
                              {
                              cout<<"program";
                              }
                              else if (a==5)//是否是周五
                              {
                              cout<<"read";
                              }
                              else if (a==6)是否是周六
                              {
                              cout<<"math";
                              }
                              else//以上都不是
                              {
                              cout<<"rest";
                              }
                              return 0;
                              }
                              
                              </span>

                              信息

                              ID
                              666
                              时间
                              1000ms
                              内存
                              64MiB
                              难度
                              4
                              标签
                              递交数
                              8042
                              已通过
                              3687
                              上传者