70 条题解

  • 24
    @ 2022-8-9 21:27:10

    在这里考的是分支问题,只需要用 if-else 即可 这里提供两种思路:①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;
        return 0;
    }
    

    第二种:②空瓶法

    #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;
    }
    
    • @ 2024-2-3 15:33:36

      不用这么麻烦,这样依然AC: #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; }

    • @ 2024-3-17 16:28:15

      @

      #include<iostream>
      using namespace std;
      int main()
      {
          int a,b;
          cin>>a>>b;
          if(a>b)
          {
              cout<<b<<" "<<a;
          }
          else
          {
              cout<<a<<" "<<b;
          }
      

      用不着

  • 7
    @ 2023-12-2 18:30:52

    这题不难。

    #include<iostream>
    using namespace std;
    int main()
    {
        int a,b;
        cin>>a>>b;
        if(a>b)
        {
            cout<<b<<" "<<a;
        }
        else
        {
            cout<<a<<" "<<b;
        }
    

    直接一个if else语句搞定 制作不易,求点赞👍。

    • 6
      @ 2022-5-31 16:56:53

      别被题目唬住了,我也是提供两种思路,第一种比较烦,可以用数组,具体可以看看我的其他有数组交换的代码,不推荐。第二种,if-else的简单判断,上核心代码!

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

      这里推荐一个万能头文件

      #include <bits/stdc++.h>
      

      日常第二十二题,嗨害嗨~~~

      • @ 2023-8-19 13:37:58

        #include <iostream 算啥

      • @ 2023-8-25 20:52:55

        j就是@

        #include <iostream>
        using namespace std;
        int main()
        {
            int n,sum,num;
            cin >> n;
            sum=(n-2)*(n-2)*1;
            num=(n-4)*(n-4)*2;
            if(sum>num)
            {
                cout << sum;
            }
            else
            {
                cout << num;
            }
            return 0;
        }
        
      • @ 2024-2-23 19:49:50

        @赫赫有名#include <iostream是不万能的头文件。

    • 3
      @ 2023-10-3 18:14:32
      #include <bits/stdc++.h>
      using namespace std;
      
      int a,b;
      int main()
      {
          cin>>a>>b; //输入数组
          if(a>b){ //判断大小
              cout<<b<<' '<<a; //如果a>b,倒序输出
              return 0; //如果a>b,输出后可以直接停止脚本
          }
          cout<<a<<' '<<b; //否则直接输出
          return 0;
      }
      
      • 3
        @ 2023-8-31 13:59:16

        很简单,求赞。

        #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;
        }
        
      • 3
        @ 2023-8-28 11:12:01
        #include <cstdio>
        int main(){int a,b;scanf("%d%d",&a,&b);printf("%d %d",a,b);}
        

        全网最短代码!!!

        • 2
          @ 2024-1-3 19:47:11

          我其实一开始错了,没加else(别笑我......

          #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;
          }
          
          
          • 2
            @ 2023-8-28 16:35:53

            本蒟蒻的第(忘了)篇题解

            真搞不懂为什么最后写一句”本题主要思考:如何交换2个变量的数值?“ 题目链接:P672 【基础】交换两数


            分析一下题目,这道题可以使用两种方法来解。

            方法一:一个一个交换

            代码如下:

            #include <bits/stdc++.h>//用万能头文件就行
            using namespace std;//创建命名空间
            int main ()//我赌没人敢不写
            {
            	int a, b, c;//定义三个整数型变量
            	cin >> a >> b;//输入两个数字
            	if (a > b)//如果a比b大
            	{
            		c = a;//借助空变量完成交换
                    a = b;//同上
                    b = c;//同上
            	}
            	cout << a << " " << b;//输出就行,注意中间的空格
            	return 0;//保持return 0; 的好习惯
            }
            

            方法二:直接使用函数

            swap函数我在第一篇题解里有讲,主要用于交换数组其中某两个元素和变量所存放的数值

            AC代码:

            #include <bits/stdc++.h>//定义万能头
            using namespace std;//创建命名空间
            int main ()//定义主函数main函数
            {
            	int a, b;//定义两个数a和b
            	cin >> a >> b;//输入a和b
            	if (a > b)//如果a大于b
            	{
            		swap (a, b);//使用swap函数交换两个变量的值
            	}
            	cout << a << " " << b;//输出两个变量,注意中间有空格
            	return 0;//保持好习惯
            }
            
            完结撒花!!!🎉️ 🎉️
            • 2
              @ 2023-8-24 19:58:08
              #include<iostream>
              using namespace std;
              int main()
              {
                  int a,b;
                  cin>>a>>b;
                  if(a>b)
                  {
                      cout<<b<<" "<<a;
                  }
                  else
                  {
                      cout<<a<<" "<<b;
                  }
              }……
              
              • 2
                @ 2023-8-23 22:04:19

                非常简单,上代码!

                #include <iostream>
                using namespace std;
                int main()
                {
                    int a,b,x;
                    cin>>a>>b;
                    if (a>b)
                    {
                        x=a;
                        a=b;
                        b=x;
                    }
                    cout<<a<<" "<<b;
                    return 0;
                }
                C++萌新~
                
                • 2
                  @ 2023-8-23 11:02:01
                  #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;
                  }点个赞吧!已AC✔
                  可复制!
                  
                  • 2
                    @ 2023-8-21 15:57:13
                    #include <iostream>
                    using namespace std;
                    int main()
                    {
                        int a,b;
                        cin>>a>>b;
                        if (a>b)
                        {
                            cout<<b<<" "<<a;
                            return 0;
                        }
                        cout<<a<<" "<<b;
                    }
                    
                    • 2
                      @ 2023-8-20 20:25:41

                      #include <iostream> using name space std; int main() { int a, b; cin >> a >> b; if (a > b) { b == a } else { a == b } cout << a << " " << b; return 0; 只要定义两个变量就可以了

                      • 2
                        @ 2023-8-19 19:55:30
                        #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;
                        }
                        
                        
                        • 2
                          @ 2023-8-14 12:41: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;
                              return 0;
                              //cout<<"发表一个题解,全代码,AC过了,0.0s过,【此题解为我学完1,2章的算是一个见证,拿走吧,不要❤️ 】"
                          }
                          
                          • 2
                            @ 2022-11-2 19:48:42

                            ``very easy 只要一个临时变量就OK!! 上代码!!!!!!

                            #include <iostream>
                            using namespace std;
                            int main()
                            {
                                int a,b,c;
                                cin>>a>>b;
                                if(a>b){
                                    c=a;
                                    a=b;
                                    b=a;  
                                    cout<<a<<" "<<b;
                                }  
                                else
                                    cout<<a<<" "<<b;
                            }
                            

                            ``

                            • 1
                              @ 2024-2-20 18:02:12
                              #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;
                              }
                              
                              • 1
                                @ 2024-1-25 16:45:35

                                很简单!!!

                                首先判断a,b的大小,如果a大于b,则cout<<b<<" "<<a;否则cout<<a<<" "<<b~~~

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

                                HAPPY

                                • 1
                                  @ 2023-12-9 19:06:51

                                  #include<iostream> using namespace std; int main() { int a , b; cin >> a >> b; if (a > b) { swap(a,b); } cout << a << " " << b; return 0; }

                                  • 1
                                    @ 2023-8-27 18:02:58

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

                                    信息

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