88 条题解

  • -1
    @ 2022-7-7 21:03:11

    也可以用0-n

    • -2
      @ 2022-8-23 20:16:10

      #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n>=0) { cout << n; } else { cout << n*-1; } return 0; }

      • -2
        @ 2022-8-22 18:40:45

        嘻嘻,简洁的代码来喽!!

        image

        #include<bits/stdc++.h>
        using namespace std;
        int main(){
            int n;
            cin >> n;
            if(n < 0) cout << n - n - n;  //那-5举例-5 - -5 = 0  0 - -5 = 5
            else cout << n;  //正数的绝对值就是他本身这不用我说了吧
            return 0;
        }
        
        • -2
          @ 2022-8-22 17:06:32
          if (n >= 0)
              {
                  cout << n;
              }
              else
              {
                  cout << n*-1;
              }
          
          • -2
            @ 2022-8-21 20:51:13

            不用定义两个变量,也不用if...else的题解

            int n;
            scanf("%d", &n); // 输入
            if (n < 0) {
            	n = -1 * n; // 如果是负数就取反
            }
            printf("%d", n); // 输出
            
            • -2
              @ 2022-8-16 12:08:52

              两个结果?用if - else语句最合适了。
              如果是负数的话,就转换为正数就行了 (0不用转换!)
              比如-3,转化就可以写0 - (-3) = 0 + 3 = 3。
              对吧?上代码!

              #include<bits/stdc++.h>
              using namespace std;
              int main()
              {
                  int x;
                  cin >> x;
                  if (x < 0) cout << 0 - x << endl;
                  else cout<< x << endl;
                  return 0; 
              }
              

              小盆友们,你们学废了吗?

              • -2
                @ 2022-8-6 17:59:13

                its/s简单的判断,直接输入,输出用abs直接就出来了,不说多直接上代码。

                #include  <bits/stdc++.h>
                using namespace std;
                int main()
                {
                int n;
                cin>>n;
                cout<<abs(n);
                return 0;
                }
                
                • -3
                  @ 2022-8-3 16:28:08

                  懒得判断的话,可以直接平方开根号,我爱sqrt。

                  
                  

                  #include <iostream> #include <cmath> using namespace std;

                  int main() { int m; cin>>m; cout<<sqrt(m*m); return 0; }

                  
                  

                  信息

                  ID
                  345
                  时间
                  1000ms
                  内存
                  16MiB
                  难度
                  5
                  标签
                  递交数
                  10963
                  已通过
                  4510
                  上传者