22 条题解

  • 1
    @ 2023-6-16 13:18:39

    解析

    输入两个数a, b,判断两个数是否存在一个大于等于60,一个小于等于60。

    枚举所有情况,表示在if语句当中即可。

    易错点

    注意括号的使用。

    题解

    #include <iostream>
    using namespace std;
    int main()
    {
        int a, b;
        cin >> a >> b;
        if ((a >= 60 && b < 60) || (a < 60 && b >= 60))
        {
            cout << 1;
        }
        else
        {
            cout << 0;
        }
        return 0;
    }
    
    • 0
      @ 2024-6-5 20:26:14

      题解 c++

      #include <bits/stdc++.h> //hetao4040809
      using namespace std;
      int main()
      {
          float x,y;
          cin>>x>>y;
          if((x<60&&y>=60)||(y<60&&x>=60))
          {
              cout<<1;
          }
          else 
          {
              cout<<0;
          }
          return 0;
      }
      
      • 0
        @ 2024-4-12 20:54:37
        #include<iostream>
        using namespace std;
        int main()
        {
            int a,b;
            cin >> a >> b;//依次输入语文和数学成绩
            if (a<60 && b>=60)//判断是否语文不合格
            {
                cout << 1;
            }
            else if (a>=60 && b<60)//判断是否数学不合格
            {
                cout << 1;
            }
            else//都不成立
            {
                cout << 0;
            }
            return 0;
        }
        
        • 0
          @ 2024-2-14 19:00:12
          #include <bits/stdc++.h>
          using namespace std;
          int n,m;
          bool b=true ;
          int main()
          {
              cin>>n>>m;
              if(n<60&&m>=60||n>=60&&m<60){
                  cout<<"1";
              }
              else{
                  cout<<"0";
              }
              }
          
          1. 包含头文件 <bits/stdc++.h>:这是一个非标准的头文件,通常在某些编译器(如GCC)中可用,用于包含几乎所有标准库头文件。使用这个头文件可以方便编程。
          2. 使用命名空间 std:这样可以直接使用标准库中的对象和函数,而不需要每次都加上 std:: 前缀。
          3. 定义全局变量 nm,用于存储从输入中读取的两个整数。
          4. 定义全局布尔变量 b 并初始化为 true。但这个变量在代码中并没有被使用,因此是多余的。
          5. 定义 main 函数,它是C++程序的入口点。
          6. main 函数中,从标准输入读取两个整数 nm
          7. 使用 if 语句判断 nm 的值:
            • 如果 n 小于60且 m 大于或等于60,或者 n 大于或等于60且 m 小于60,则输出 "1"。
            • 否则,输出 "0"。
          注意,如果出现下列警告不用管
          foo.cc: In function 'int main()':
          foo.cc:8:12: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
               if(n<60&&m>=60||n>=60&&m<60){
                  ~~~~^~~~~~~
          
          • 0
            @ 2023-6-18 14:38:08
            #include<iostream>
            using namespace std;
            int main()
            {
            long long a,b;
            cin>>a>>b;
            cout<<(a<60^b<60);//只要及格情况不一样就好了
            return 0;
            }
            
            • 0
              @ 2023-6-17 17:50:07
              #include <iostream>
              using namespace std;
              int main()
              {
                  int a,b;
                  cin>>a>>b;
                  if (a>60 && b>60)
                      cout<<0;
                  if (a<60 && b<60)
                      cout<<0;
                  if (a<60 || b<60)
                  {
                      if (a>=60 || b>=60)//必须要有一个大于60
                          cout<<1;
                  }
                  return 0;
              }
              //我一开始对九个,错一个,发现是两门不及格也是0。我这个代码可能有些傻,但是这要思路比较清晰。
              
              • -1
                @ 2024-5-24 17:11:43
                #include<iostream>
                #include<cstdio>
                #include<cmath>
                #include<iomanip>
                using namespace std;
                int main()
                {
                    int a,b,c;
                    cin >> a >> b;
                    c = 0;
                    if (a < 60)
                        c += 1;
                    if (b < 60)
                        c += 1;
                    if (c == 1)
                        cout << 1;
                    else
                        cout << 0;
                    return 0;
                }
                
                • -1
                  @ 2024-4-9 16:10:48
                  #include <iostream>
                  #include <iomanip>
                  #include <cstdio>
                  #include <cmath>
                  using namespace std;
                  int main()
                  {
                      long long a,b;//创建a,b
                      cin >> a >> b;//输入成绩
                      if ((a<60 && b>60) || (a>60 && b<60))//判断是否为“倒霉蛋”
                      {
                          printf("1");//装一下......
                      }
                      else
                      {
                          cout << "0";//输出
                      }
                      return 0;
                  }
                  //(给个赞吧!!
                  
                  • -1
                    @ 2023-11-17 20:57:10
                    #include <iostream>
                    using namespace std;
                    int main()
                    {
                        int a , b;
                        cin >> a >> b;
                        if(((a < 60)&&(b >= 60))||((a >= 60)&&(b < 60)))
                        {
                            cout << "1";
                        }
                        else
                        {
                            cout << "0";
                        }
                        return 0;
                    }
                    
                    • -1
                      @ 2023-8-6 20:56:43

                      #include <bits/stdc++.h> using namespace std; int main() { int y,s; cin>>y>>s; if(y<60 || s<60) { if(y>=60 || s>=60) { cout<<1; } else { cout<<0; } } else { cout<<0; } return 0; } #要注意只有一门功课不及格啊啊啊啊啊啊啊啊啊啊啊啊啊啊!!!!!

                      • -1
                        @ 2023-7-27 19:23:08
                        #include<iostream>
                        using namespace std;
                        int main()
                        {
                            int n, m;
                            cin >> n >> m;
                            if(n < 60 && m < 60)
                            {
                            cout << "0";
                            }
                            else if (n < 60 || m < 60)
                            {
                            cout << "1";
                            }
                            else
                            {
                            cout << "0";
                            }
                            return 0;
                        }
                        
                        • -1
                          @ 2023-7-20 17:06:29
                          #include <iostream>
                          using namespace std;
                          int main()
                          {
                              int a, b;
                              cin >> a >> b;
                              if ((a >= 60 and b < 60) or (a < 60 and b >= 60))
                              {
                                  cout << 1;
                              }
                              else
                              {
                                  cout << 0;
                              }
                              return 0;
                          }//简单计算即可`
                          
                          • -1
                            @ 2023-7-7 20:09:07

                            解析

                            输入两个数yu, shu,判断两个数是否存在一个大于等于60,一个小于等于60。

                            枚举所有情况,表示在if语句当中即可。

                            易错点

                            注意括号的使用。😄 😄

                            #include <iostream>
                            using namespace std;
                            
                            int main()
                            {
                               int yu,shu;
                               cin >> yu >> shu;
                               (shu < 60 && yu >= 60)||(shu >= 60 && yu < 60) ? cout << 1:cout << 0;
                               return 0; 
                            }
                            
                            • -1
                              @ 2023-6-18 11:14:36
                              
                              
                              #include <iostream>
                              using namespace std;
                              int main()
                              {
                              int a1,b1,bjg=0;//a1:语文成绩 b1:数学成绩 bjg:不及格科目数
                              cin >> a1 >> b1;
                              if(a1<60)//判断语文是否为不及格
                              bjg += 1;
                              if(b1<60)//判断数学是否为不及格
                              bjg += 1;
                              if(bjg == 1)//判断是否只有一门课不及格
                              cout << 1;
                              else
                              cout << 0;
                              }
                              
                              
                              
                              • -1
                                @ 2023-6-17 22:51:04

                                有一门课不及格的学生

                                思路

                                刚好只有一门课不及格,所以不是语文不及格、数学及格,就是数学不及格、语文及格,要用“&&”和“||”

                                获取两门功课成绩,判断两门功课((语文 < 60 && 数学 >= 60) || (数学 < 60 && 语文 >= 60))

                                参考代码

                                #include <iostream>
                                using namespace std;
                                int main() {
                                    int c, m;
                                    cin >> c >> m;
                                    if ((c < 60 && m >= 60) || (m < 60 && c >= 60)) {
                                        cout << 1 << endl;
                                    }
                                    else {
                                        cout << 0 << endl;
                                    }
                                    return 0;
                                }
                                
                                • -1
                                  @ 2023-6-17 16:56:25

                                  我也发一个😄 :

                                  #include <iostream>
                                  using namespace std;
                                  int main()
                                  {
                                      int chinese, math;
                                      cin >> chinese >> math;
                                      if ( (chinese < 60 && math >= 60) || (math < 60 && chinese >= 60) )
                                      // 易错易错!! 是恰好“一”科 不及格 输出1!
                                      //这也意味着 要么 语文不及格,数学及格了。
                                     // 要么 数学不及格, 语文及格了。两种情况就用 ||。
                                          cout << 1;
                                      else
                                          cout << 0;
                                      return 0;                                                         
                                  }
                                  

                                  有错误请指出🚀️ 🚀️

                                  点个赞哦👍

                                  • -1
                                    @ 2023-6-17 16:12:50
                                    #include <iostream>
                                    using namespace std;
                                    int main()
                                    {
                                        int a,b;
                                        cin >> a >> b;
                                        if ((a < 60 && b >= 60)||(a >= 60 && b < 60))
                                            cout << "1";
                                        else
                                            cout << "0";
                                        return 0;
                                    }
                                    

                                    解析: 判断成绩是否小于60,如果有就输出1,没有就输出0。

                                    注意!!!!!! 只能有一门不及格,两门也不行(我一开始就栽在这,对九错一,懵逼了好久) 最后提醒大家,不管做练习还是考试审题都要仔细哦! 看到这里就点个赞吧!👍

                                    • -1
                                      @ 2023-6-17 13:10:31

                                      为了判断两科同时不及格的情况,只需要再用一次if判断~~😄

                                      #include <iostream>
                                      using namespace std;
                                      int main()
                                      {
                                          int a,b;
                                          cin >> a >> b;
                                          if (a < 60 || b < 60)
                                              {
                                                  if (a < 60 && b < 60)
                                                      cout << 0;
                                                  else
                                                      cout << 1;
                                              }
                                          else
                                              cout << 0;
                                      }
                                      
                                      • -1
                                        @ 2023-6-17 13:01:01

                                        一个有点离谱的解法 思路: 由题意得:分数总共有三种情况 ①都小于60 (Chinese < 60 && Maths < 60) ②有一科小于60 (Chinese < 60 || Maths < 60) ③都不小于60(我将这种情况放在了else下面,写成条件表达式即为(Chinese > 60 && Maths > 60) 所以只需要用if-else if-else分别判断三种情况就好了

                                        #include <iostream>
                                        using namespace std;
                                        
                                        int main()
                                        {
                                            int Chinese,Maths;
                                            cin >> Chinese >> Maths;
                                            if (Chinese < 60 && Maths < 60)
                                                cout << 0;
                                            else if (Chinese < 60 || Maths < 60)
                                                cout << 1;
                                            else
                                                cout << 0;
                                            return 0;
                                        }
                                        
                                        • -1
                                          @ 2023-6-16 22:17:16

                                          稍微简化了一下代码

                                          #include <iostream>
                                          using namespace std;
                                          int main(){
                                              int a,b;
                                              cin>>a>>b;
                                              cout<<((a >= 60 && b < 60) || (a < 60 && b >= 60));
                                              return 0;
                                          }
                                          

                                          信息

                                          ID
                                          149
                                          时间
                                          1000ms
                                          内存
                                          128MiB
                                          难度
                                          6
                                          标签
                                          递交数
                                          3602
                                          已通过
                                          983
                                          上传者