91 条题解

  • -1
    @ 2022-4-28 20:35:41

    算法思路:

    1. 先将三个数排序,不过因为这里只有三个数,所以我们可以先找到最大的,再找到最小的。

    2. 然后将最大的和最小的相加即可。用总和减去这个和就得到了中间的数。再检查三个数是不是相邻的,即小数+1=中间数,中间数+1=大数。

    3. 同时注意maxx和minx的初始值设立,求最大值,maxx初始应该很小,求最小值,minx初始应该很大。

        nums[1] = a;
        nums[2] = b;
        nums[3] = c;
        for (int i = 1; i <= 3; i++)
        {
            if (nums[i] > maxx)
            {
                maxx = nums[i]; // 找到最大值
            }
            if (nums[i] < minx)
            {
                minx = nums[i]; // 找到最小值
            }
        }
    

    和减去最大值和最小值的和不就是中间值吗?

    判断 minx 和 midx 和 maxx 是否相邻,相邻的两个数的差肯定是1

    
        midx = (a + b + c) - maxx - minx;
        if (minx + 1 == midx && midx + 1 == maxx)
        {
            cout << "TRUE" << endl;
        }
        else
        {
            cout << "FALSE" << endl;
        }
    
    • -1
      @ 2022-4-24 15:51:16

      鼓励大家写题解,但注意题解格式。

      给代码两端加上这个会舒服一些

      ```cpp

      你的代码

      ```

      </span>

      这个点在键盘的左上角tab上面那个键,注意切换输入法

      #include<iostream>
      using namespace std;
      int main()
      {
          int n;
          cin>>n;//这是一个注释
          return 0;
      } 
      

      请注意严禁抄袭题解,写题解不要只放代码,需加上你的思路或代码注释。

      抄袭题解一经发现直接取消成绩。

      • -2
        @ 2024-1-8 21:16:49

        我用的枚举😕 #include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; if (a+1b&&b+1c&&c-2a or a-1b&&b+2c&&a+1c or a-1c&&b-2c&&a+1b or a+2b&&b-1c&&a+1c or a-1b&&b-1c&&c+2a or a-2b&&a-1c&&b+1c) { cout << "TRUE"; } else { cout << "FALSE"; } return 0; }

        • -2
          @ 2023-10-15 16:05:20

          #include <iostream> using namespace std; int main() { int a,b,c; cin >> a >> b >> c; if ((ab-1 and bc-1)|| (ac-1 and cb-1)||(ab+1 and bc+1)|| (ac+1 and cb+1)) { cout << "TRUE"; } else if ((ba-1 and ac-1)|| (bc-1 and ca-1)||(bc+1 and ca+1)|| (ba+1 and ac+1)) { cout << "TRUE"; } else if ((cb-1 and ba-1)|| (ca-1 and ab-1)||(cb+1 and ba+1)|| (ca+1 and cb+1)) { cout << "TRUE"; } else { cout << "FALSE"; } return 0; }

          • -2
            @ 2023-8-30 13:38:47

            +1

            • -2
              @ 2023-8-19 10:17:31

              比较简洁的方式,先创建数组,然后发现只要是连续的三个整数,它们的和除以3都等于0。所以我们先用一个for循环输入数组,再进行求和,但这里精妙的地方在于,如果数组中a[1]-a[0]>2,说明已经不是连续的整数了(可以思考一下),所以,在求和的同时进行判断,上述情况不进行求和,最后用if语句判断如果取余3=0,那么就是连续的啦!

              #include <iostream> using namespace std; int main() { int a[3],sum=0; for(int i=0;i<=2;i++) { cin>>a[i]; } for(int j=0;j<=2;j++) { if(a[j+1]-a[j]<=2) sum+=a[j]; } if(sum%3==0) { cout<<"TRUE"; } else { cout<<"FALSE"; } return 0;

              
              
              • -2
                @ 2023-8-18 20:12:10
                #include <bits/stdc++.h> 
                using namespace std;
                int main()
                {
                    int a,b,c,z,j,k;
                    cin>>a>>b>>c;
                    if (a>b && b>c)
                    {
                        z=a;
                        j=b;
                        k=c;
                    }
                    else if (a>c && c>b)
                    {
                        z=a;
                        j=c;
                        k=b;
                    }
                    else if (b>a && a>c)
                    {
                        z=b;
                        j=a;
                        k=c;
                    }
                    else if (b>c && c>a)
                    {
                        z=b;
                        j=c;
                        k=a;
                    }
                    else if (c>b && b>a)
                    {
                        z=c;
                        j=b;
                        k=a;
                    }
                    else if (c>a && a>b)
                    {
                        z=c;
                        j=a;
                        k=b;
                    }
                    if (z-j==1 && j-k==1)
                    {
                        cout<<"TRUE"<<endl;
                    }
                    else
                    {
                        cout<<"FALSE"<<endl;
                    }
                    
                    return 0;
                }
                
                • -2
                  @ 2022-10-4 19:46:07

                  👍 🎉️

                  • -2
                    @ 2022-9-15 19:45:36

                    #include <iostream> using namespace std; int main() { int a1, a2 ,a3,z; cin>>a1>>a2>>a3; z=a1+a2+a3; if (z/3a1){ cout<<"TRUE"; } else{ if (z/3a2){ cout<< "TRUE"; } else{ if (z/3==a3){ cout<<"TRUE"; } else{ cout<<"FALSE"; } } } }

                    • @ 2022-10-12 17:38:46

                      如有代码,请使用markdown。

                      ——kkksc03

                  • -2
                    @ 2022-8-29 21:28:55

                    上代码! 基本思路是将三个数排序后进行比较

                    #include <bits/stdc++.h>
                    using namespace std;
                    int main()
                    {
                        int a[3]; //定义数组
                        for (int i=0;i<3;i++)
                        {
                            cin>>a[i];  //输入
                        }
                        sort(a,a+3); //排序
                        if (a[0]+1==a[1] && a[1]+1==a[2]) //判断三个数是否是相邻数
                        {
                            cout<<"TRUE"; //不要写成“TURE”哦
                        }
                        else
                        {
                            cout<<"FALSE";
                        }
                        return 0;
                    }
                    
                    • -17
                      @ 2022-7-9 16:54:34

                      if(x > a) { max = x; } else { max = a; } if(b > max) { max = b; } //找到最大值

                      //找到最小值…… middle = (x + a + b) - max - min; //定义"middle" if(min + 1 == middle and middle + 1 == max) { cout << "TRUE"; } else { cout << "FALSE"; } //判断与输出

                      【入门】判断三个整数是否相邻

                      信息

                      ID
                      36
                      时间
                      1000ms
                      内存
                      16MiB
                      难度
                      6
                      标签
                      递交数
                      10083
                      已通过
                      2948
                      上传者