70 条题解

  • 0
    @ 2023-8-7 11:05:17

    easy题 三种思路 ①函数结构

    using namespace std;
    void a(){
    int a = 0,b = 0;
    cin >> a>> b;
    if (b<a)
    cout << b << " " << a;
    else cout << a << " "<< b;
    }
    int main(){
    a();
    }
    

    ②普通计算(空瓶)


    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int c,a,b;
        cin>>a>>b;
        if(a>b)
        {
        c=a;a=b;b=c;
        }
        cout << a << " "<< b;
        return 0;
    }
    

    ③swap函数


    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int a, b;
        cin >> a >> b;
        if (a > b) 
        swap(a, b);
        cout << a << " " << b;
    }
    

    思路仅供参考,不予复制

    • 0
      @ 2023-8-4 6:24:59

      相当简单这道题,也可以用swap函数来解

      #include <iostream>
      using namespace std;
      int a,b;
      int main()
      {
          cin >> a>>b;
          if (a>b)//判断a是否大于b
          {
              int t=b;//定义临时变量t存储b的数值,如果直接a=b,b=a,那就很尴尬了
              b=a;
              a=t;
          }
          cout <<a<<" "<<b;
          return 0;
      }
      
      • 0
        @ 2023-6-12 16:17:04

        #include<bits/stdc++.h> using namespace std; int main() { int a,b; cin >> a>> b; if(a>b) {

        cout << b << " "<< a;		
        }
        else
        {
        	cout << a << " " << b;
        }
        return 0;
        

        }

        • 0
          @ 2023-6-12 16:16:10

          #include<bits/stdc++.h> using namespace std; int main() { int a,b; cin >> a>> b; if(a>b) {

          cout << b << " "<< a;		
          }
          else
          {
          	cout << a << " " << b;
          }
          return 0;
          

          }

          • 0
            @ 2023-6-4 11:21:17
            #include <iostream>
            using namespace std;
            int main()
            {
                int t,a,b;
                cin>>a>>b;
                if(a>b)
                {
                t=a;
                a=b;
                b=t;
                }
                cout<<a<<" "<<b;
                return 0;
            }
            求点赞```
            • 0
              @ 2023-3-28 22:12:55
              #include<bits/stdc++.h>
              using namespace std;
              int main()
              {
                  int a,b;
                  cin>>a>>b;
                  cout<<min(a,b)<<" "<<max(a,b);
                  return 0;
              }
              
              • 0
                @ 2023-3-12 19:49:18
                //这道题很简单,给大家推荐L6会学的swap()函数,废话不多说,代码(Ac哦~)走起!
                #include<bits/stdc++.h>
                using namespace std;
                int a, b;
                int main()
                {
                    cin >> a >> b; //输入a和b
                    if (a > b) //如果a大于b
                    {
                        swap(a, b); //交换两个数
                    }
                    cout << a << " " << b; //输出
                    return 0;
                }
                //编码不易,先点赞后抱走啊~😄
                
                • @ 2023-8-13 19:32:16

                  我现在才学完L2......

              • 0
                @ 2023-2-26 13:36:16
                #include <bits/stdc++.h>
                using namespace std;
                int main()
                {
                    int a,b,z;
                    cin >> a >> b;
                    if (a > b)
                    {
                        z = a;
                        a = b;
                        b = z;
                        cout << a << " " << b;
                    }
                    else
                    {
                        cout << a << " " << b;
                       
                    }
                这里涉及到一个中转的知识,用一个变量存放先改变的一个数,不过很简单,答不对,哎,当成给你吃了!
                
                
                
                • 0
                  @ 2023-2-12 11:06:26
                  #include <bits/stdc++.h>
                  int main(){   
                      int a,b;
                      std::cin >> a >> b;
                      if(a>b){std::swap(a,b);}
                      std::cout << a << " " << b;
                      return 0;
                  }
                  

                  最短题解来啦,先点赞,再抱走

                  • 0
                    @ 2023-1-20 21:45:31
                    //思路:定义一个临时变量,可以想象成一个桶帮我们储存 a 然后如果a>b,再把c(也就是a的值)赋值给b,最后输出即可~
                    #include <bits/stdc++.h>
                    using namespace std;
                    int main()
                    {
                        int a,b,c;//这是一个注释
                        cin >> a >> b;
                        if (a>b)
                        {
                            a = c;
                            a = b;
                            b = c;
                        }
                        cout << a << " " << b;
                        return 0;
                    }
                    //复制?点赞拿走(滑稽)
                    
                    • 0
                      @ 2023-1-9 19:21:31

                      直接使用函数swap

                          if(a > b)
                          {
                              swap(a,b);
                              cout << a <<" "<< b;
                          }
                          else
                          {
                              cout << a <<" "<< b;
                          }
                      

                      简单爆棚~

                      • 0
                        @ 2022-10-16 20:51:02

                        不解释了自己看

                        #include <bits/stdc++.h>
                        using namespace std;
                        int a,b,c;
                        int main()
                        {
                            cin>>a>>b;
                            if (a>b)
                            {
                                a=c;
                                a=b;
                                b=c;
                            }
                            cout<<a<<" "<<b;
                        }
                        
                        • 0
                          @ 2022-10-4 19:50:44
                          #include<iostream>
                          using namespace std;
                          int main()
                          {
                              int a;
                              int s;
                              int d;
                              cin >> a;
                              cin >> s;
                              if (a > s)
                              {
                                  d = s;
                                  s = a;
                                  a = d;
                                  cout << a << " " << s;
                              }
                              else
                              {
                                  cout << a << " " << s;
                              }
                          }
                          
                          • 0
                            @ 2022-8-29 17:27:33
                            #include <iostream>
                            using namespace std;
                            int main()
                            {
                            int a, b;
                            cin >> a >> b;//输入
                            if (a < b)
                            {
                                cout << a  << " " << b;//别忘了" "
                            }
                            else//否则b a
                            {
                                cout << b << " " << a;//反着输出
                            }
                            return 0;
                            }
                            
                            • 0
                              @ 2022-8-27 9:52:04

                              这道题很简单,用一个if ......else ......语句就可以了。 话不多说,上代码!!! TIP:这里用的是c++语言

                              #include <iostream>

                              using namespace std;

                              int main()

                              {

                              int a, b;
                              
                              cin >> a >> b;
                              
                              if (a > b)
                              
                              {
                                  
                                  cout << b << " " << a;
                              
                              }
                              
                              else
                              
                              {
                                  
                                  cout << a << " " << b;
                              
                              }
                              
                              return 0;
                              

                              }

                              • 0
                                @ 2022-8-24 21:36:26

                                其实不用十行,输出大值 小值就行。

                                #include <bits/stdc++.h>
                                using namespace std;
                                int a,b;
                                int main()
                                {
                                	cin >> a >> b;
                                	cout << min(a,b) << " " << max(a,b);	return 0;
                                }
                                
                                • 0
                                  @ 2022-8-22 18:23:20

                                  个人认为这是Level2中最简单的题目 核心代码:swap函数

                                  swap(a,b);
                                  

                                  完整代码:

                                  #include<bits/stdc++.h> 
                                  using namespace std;
                                  int main()
                                  {
                                      int a,b;
                                      cin>>a>>b;
                                      if(a>b)
                                          swap(a,b);
                                          cout<<a<<" "<<b;
                                      else
                                          cout<<a<<" "<<b;
                                      return 0;
                                  }
                                  

                                  当然,不懂swap函数就可以用简单的if..else语句,核心代码:

                                  if(a>b)
                                      cout<<b<<" "<<a;
                                  else
                                      cout<<a<<" "<<b;
                                  

                                  完整代码:

                                  #include<bits/stdc++.h>
                                  using namespace std;
                                  int main()
                                  {
                                      int a,b;
                                      cin>>a>>b;
                                      if(a>b)
                                          swap(a,b);
                                          cout<<a<<" "<<b;
                                      else
                                          cout<<a<<" "<<b;
                                      return 0;
                                  }
                                  
                                  • 0
                                    @ 2022-8-22 11:31:13

                                    最简洁的代码了

                                    #include<bits/stdc++.h>
                                    using namespace std;
                                    
                                    int main()
                                    {
                                    	int a,b;
                                    	cin >> a >> b;
                                    	cout << min(a,b) << " " << max(a,b);
                                    }
                                    
                                  • 0
                                    @ 2022-8-21 15:24:09

                                    这道题超超超超超超超超简单,只要条件判断就可以啦~

                                    #include <iostream>
                                    using namespace std;
                                    int main()
                                    {
                                        int a, b;
                                        cin >> a >> b;
                                        if (a > b)
                                        {
                                            cout << b << " " << a;
                                        }
                                        else
                                        {
                                            cout << a << " " << b;
                                        }
                                        return 0;
                                    }
                                    
                                    • 0
                                      @ 2022-8-16 19:03:42

                                      太简单了

                                      if (a > b)
                                          {
                                              cout << b << " " << a;
                                          }
                                          else
                                          {
                                              cout << a << " " << b;
                                          }
                                      

                                      信息

                                      ID
                                      672
                                      时间
                                      1000ms
                                      内存
                                      16MiB
                                      难度
                                      3
                                      标签
                                      递交数
                                      4897
                                      已通过
                                      2714
                                      上传者