70 条题解

  • 1
    @ 2023-8-26 10:19:15

    ①输入,②判断,③更换,④输出,完成!(第一次发题解,请多指教)

    #include <iostream>
    using namespace std;
    int main()
    {
        int a,b,x;
        cin >> a >> b;
        if (a > b)
        {
            b = x;
            a = b;
            x = a;
        }
        cout << a << " " << b;
        return 0;
    }
    
    • 0
      @ 2024-5-9 22:28:31

      纯种比大小!

      #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
        @ 2024-3-23 10:51:46
        #include<bits/stdc++.h>
        using namespace std;
        int main(){
            int a, b, c;//c是中间变量,是空的,用来装b、a变量。
            cin >> a >> b;
            if(a > b){
                c = a;
                a = b;
                b = c;
            }
            cout << a << " " << b;
        }//已AC
        
        • 0
          @ 2023-8-22 10:28:18

          高端的题目,往往要用最简单的方式解决(狗头) 这是树

          #include <iostream>
          using namespace std;
          
          struct TreeNode {
              int val;
              TreeNode* left;
              TreeNode* right;
          
              TreeNode(int x) : val(x), left(NULL), right(NULL) {}
          };
          
          TreeNode* insertNode(TreeNode* root, int val) {
              if (root == NULL) {
                  return new TreeNode(val);
              }
          
              if (val < root->val) {
                  root->left = insertNode(root->left, val);
              } else {
                  root->right = insertNode(root->right, val);
              }
          
              return root;
          }
          
          void inOrderTraversal(TreeNode* root) {
              if (root != NULL) {
                  inOrderTraversal(root->left);
                  cout << root->val << " ";
                  inOrderTraversal(root->right);
              }
          }
          
          int main() {
              int a, b;
              cin >> a >> b;
          
              if (a > b) {
                  swap(a, b);
              }
          
              TreeNode* root = NULL;
              root = insertNode(root, a);
              insertNode(root, b);
          
              inOrderTraversal(root);
          
              return 0;
          }
          

          已AC

          • @ 2023-8-23 11:04:00

            真狗!没你这么长的,也没你这么蠢的!

          • @ 2023-8-24 20:21:13

            没这么长的好吧??

          • @ 2023-8-24 20:21:29

            啊对对对@

          • @ 2023-9-1 19:27:05

            @ 我爱怎么写就怎么写,管你们两个什么事? 你这么牛逼o( ̄▽ ̄)d 能复杂就复杂,你**你自己不会写说别人干嘛,当网络喷有意思吗???

          • @ 2024-2-20 18:06:26

            这东西真长,说得没错,@hetao7180554

          • @ 2024-2-20 18:08:00

            啊对对对

        • 0
          @ 2023-8-17 15:58:47
          #include<iostream>
          using namespace std;
          int main()
          {
              int a, b;
              cin >> a >> b;
              cout << a << " " << b;
              return 0;
          } 
          //我爱钻空
          
          • 0
            @ 2023-8-16 10:16:10
            #include <iostream>
            using namespace std;
            int main()
            {
                int a,b,c;
                cin >> a >> b;
                if(a > b)
                {
                    c = a;
                    a = b;
                    b = c;
                }
                cout << a << " "<< b;
            }
            
            • 0
              @ 2023-8-15 19:51:13
              #include <iostream>
              using namespace std;
              int main()
              {
                  int a, b ,c;
                  cin >> a>> b;
                  if (a > b)
                  {
                      c = a;//先将a存入c里面
                      a = b;//将a赋值为b
                      b = c;//b赋值为c
                      cout << a << " " << b;
                  }
                  else
                  {
                      cout << a << " " << b;
                  }
                  
              }**
              
              • 0
                @ 2023-8-15 13:19:11

                这是我第二次助人为乐(发题解)😄 最最最新手的代码啦!

                #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-8-14 17:00:22
                  #include <iostream>
                  using namespace std;
                  int main()
                  {
                      int a, b ,c;
                      cin >> a>> b;
                      if (a > b)
                      {
                          c = a;//先将a存入c里面
                          a = b;//将a赋值为b
                          b = c;//b赋值为c
                          cout << a << " " << b;
                      }
                      else
                      {
                          cout << a << " " << b;
                      }
                      
                  }
                  
                  • 0
                    @ 2023-8-13 19:30:27
                    #include <iostream>
                    using namespace std;
                    int main()
                    {
                        int a,b,c;
                        cin>>a>>b;
                        if (a>b)
                        {
                            c=a;//用临时变量c存储a的值。
                            a=b;//把a的值变为b的值。
                            b=c;//把b的值变为c的值(即原来a的值)。
                        }
                        cout<<a<<" "<<b;
                        return 0;
                    }
                    
                    • 0
                      @ 2023-8-13 16:21:18

                      无脑代码罢了```

                      #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;
                      }
                      

                      thanks for watching.

                      • 0
                        @ 2023-8-13 15:12:50
                        #include <iostream>
                        using namespace std;
                        int main()
                        {
                            int a, b, c;
                            cin >> a >> b;
                            if(a > b)
                            {
                                c = a;//用c保存a的值
                                a = b;
                                b = c;
                            }
                            cout << a << " " << b;
                        	return 0;
                        }
                        
                        • 0
                          @ 2023-8-13 11:28:20
                          #include <bits/stdc++.h> 
                          using namespace std;
                          int main()
                          {
                              int m,f;
                              cin >>m;
                              cin >>f;
                              if (m>f)
                              {
                                 cout <<f<<" "<<m; 
                              }
                              else 
                              {
                                  cout <<m<<" "<<f; 
                              }
                              return 0;
                          }
                          
                          • 0
                            @ 2023-8-12 12:53:13

                            只要交换输出顺序就行了 #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
                              @ 2023-8-12 12:31:54

                              LTC这题叫不得基础题


                              #include<bits/stdc++.h>//...
                              using namespace std;
                              int main()
                              {
                                  int a,b,c;
                                  cin>>a>>b;
                                  if(a>b)
                                  {
                                      c=b;
                                      b=a;
                                      a=c;   
                                  }
                                  cout<<a<<" "<<b;
                                  return 0;
                              }
                              
                              </span>
                              • 0
                                @ 2023-8-11 14:33:48
                                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-8-9 18:08:29

                                  很简单,以下是AC过的代码,思路无误

                                  #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
                                    @ 2023-8-9 17:09:44
                                    #include <bits/stdc++.h> 
                                    using namespace std;
                                    int main()
                                    {
                                        int a,b,c;
                                        cin>>a>>b;
                                        if (a>b)
                                        {
                                        c=a;//c为临时变量
                                        a=b;
                                        b=c;
                                        }
                                        cout<<a<<" "<<b;
                                        return 0;
                                    }
                                    

                                    0.0s AC

                                    • 0
                                      @ 2023-8-8 10:04:34
                                      #include <bits/stdc++.h>
                                      using namespace std;
                                      int main()
                                      {
                                          int a, b;
                                          cin >> a >> b;
                                          if (a > b) swap(a, b);
                                          cout << a << " " << b;
                                          return 0;
                                      }
                                      
                                      • 0
                                        @ 2023-8-7 14:24:53

                                        有三种方法:


                                        一 绕过交换

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

                                        二 swap 用法:swap(变量,变量);

                                        swap(a,b);
                                        

                                        三 中间变量

                                        //for example
                                        //you have a,b,c,you want to change a,b
                                        int a,b,c;
                                        a=c;
                                        a=b;
                                        b=c;
                                        

                                        OK,That's all.Thanks for watching.

                                        信息

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