88 条题解

  • 0
    @ 2022-8-3 21:08:25

    这题也简单呀!可以先用万能头文件搞上!然后调用fabs()函数,一下子就求出绝对值啦~

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int a;
        cin >> a;
        cout << fabs(a);
        return 0;
    }
    
  • 0
    @ 2022-7-8 15:42:33

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

    题解来喽!!!

    • 0
      @ 2022-7-7 21:39:02

      题目既然没有规定不能用自带的abs函数,那就得直接用呀。 第一种方法,用自带函数

      #include <bits/stdc++.h> 
      using namespace std;
      int main()
      {
          int n,n2;
          cin >> n;
          n2 = abs(n);
          cout << n2;
          return 0;
      }
      

      第二种方法,不用函数

      #include <bits/stdc++.h> 
      using namespace std;
      int main()
      {
          int n1,n2;
          cin >> n1;
          if(n1>=0)
          {
              cout << n1;
          }
          else
          {
              n2 = -1*n1;
              cout << n2;
          }
      }
      
      • 0
        @ 2022-6-30 10:29:07

        #include <bits/stdc++.h> #include <cmath> using namespace std; int main() { int n; cin >> n; cout << abs(n); return 0; }

        • 0
          @ 2022-5-23 15:52:29

          题解:输入只有两种可能,正数、负数 最后输出绝对值,就是个正数。 那就是一个if的判断(负数小于0), 就用0减去负数就能得到它的绝对值,也可以用负数乘以-1得到绝对值。 反之就是大于0,或者等于0的,直接输出就行了。

          • 0
            @ 2022-5-15 9:34:14

            #include <iostream> using namespace std; int main() { int n; cin>>n; if(n<0) { cout<<n*-1; } else { cout<<n; } return 0; }

            • -1
              @ 2023-8-26 22:03:38
              #include<bits/stdc++.h>
              using namespace std;
              int main(){
              int n;
              cin >> n;
              cout << abs(n);
              return 0;
              }
              

              有了这个万能头,可以直接用abs()!!!

              
              
              • -1
                @ 2023-8-19 16:39:19

                【入门】求绝对值

                这题难度也有一点提升。 要做这题,我们要先知道:绝对值是什么? 这时候我们就要道题目中去找了。

                负数的绝对值是它的相反数(相反数的概念,5的相反数数-5,-2的相反数是2),0的绝对值任然是0。

                如果我们只用学过的代码就显得太复杂了。 所以,我们要认识一个新东西——函数。求绝对值的函数是abs()。 但是,<iostream>头文件中不包含这个函数。所以,我们也要导入一个新的头文件——<bits/stdc++.h>,也就是我们所说的万能头文件。


                AC代码

                #include <bits/stdc++.h>
                using namespace std;
                int main()
                {
                    int n;
                    cin >> n;//创建并导入变量n 
                    cout << abs (n);/*直接使用绝对值函数
                	注意:<iostream>头文件里没有这个函数!!!*/ 
                    return 0;
                }
                //一手交赞一手交货
                
                • -1
                  @ 2023-8-17 10:19:44

                  这题简单,我们直接用绝对值函数abs()就可以了

                  int n;
                  cin >> n;
                  cout << abs(n);
                  
                  • -1
                    @ 2023-8-15 19:37:45
                    • -1
                      @ 2023-8-13 11:51:18

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

                      • -1
                        @ 2023-8-7 10:10:12
                        #include <bits/stdc++.h>
                            using namespace std;
                            int main()
                            {
                                int n;
                                cin >> n;
                                if (n>=0)
                                {
                                    cout << n;
                                }
                                else
                                {
                                    cout << n*-1;//注意!不是-n或cout << "-" << n;
                                }
                                return 0;
                            }
                        //求赞赞
                        
                        • -1
                          @ 2023-8-6 22:10:51
                          #include <iostream>
                          using namespace std;
                          int main()
                          {
                              int n;
                              cin>>n;
                              if(n>=0)
                              {
                                  cout<<n;
                              }
                              else
                              {
                                  cout<<n*-1;
                              }
                              return 0;
                          }
                          

                          借问一下,大家知道什么好用的c++编辑器image

                        • -1
                          @ 2023-8-4 20:17:16

                          降维打击

                          #include <bits/stdc++.h>
                          using namespace std;
                          int main(){
                              int a,b;
                              cin>>a;
                              b=abs(a);
                              cout<<b;
                          }
                          
                          • -1
                            @ 2023-8-3 21:43:48

                            本蒟蒻的第一篇题解

                            这题很简单,用不着判断,用函数就行……


                            这是题目链接 P345 【入门】求绝对值)


                            这里给大家普及一下,abs函数在c语言中,只对int类型有效,作用是求整数的绝对值,调用的头文件是 abs函数在c++中,在最早的c98版本中,只对double,float,long double类型生效,不支持int 类型,作用是求数据的绝对值。从c++ 11开始,增加了对int 数据的支持。需要调用的头文件是cmath


                            下面附上AC CODE:

                            #include <bits/stdc++.h>//定义万能头就不需要用cmath了
                            using namespace std;//定义命名空间
                            int main ()//不写的都是大佬
                            {
                                int a;//定义整数变量a
                                cin >> a;//输入a
                                a = abs(a);//把a的值替换为用abs函数取过绝对值的a
                                cout << a;//输出a
                                return 0;//保持return 0; 的好习惯
                            }
                            

                            😄 希望通过

                            • -1
                              @ 2023-8-1 15:15:19
                              #include<iostream>
                              using namespace std;
                              int main(){
                                   int n;
                                   cin>>n;
                                   if(n<0){
                                        n=~(n-1)//~号,括号里填n-1
                                   }
                                   cout<<n//输出n
                                   return 0;//正常结束,1表示异常结束
                              }
                              
                              • -1
                                @ 2023-8-1 10:28:35
                                #include <bits/stdc++.h>
                                    using namespace std;
                                    int main()
                                    {
                                        int n;
                                        cin >> n;
                                        if (n>=0)
                                        {
                                            cout << n;
                                        }
                                        else
                                        {
                                            cout << n*-1;//注意!不是-n或cout << "-" << n;
                                        }
                                        return 0;
                                    }
                                
                                • -1
                                  @ 2023-6-13 19:52:27
                                  #include <bits/stdc++.h>
                                      using namespace std;
                                      int main()
                                      {
                                          int n;
                                          cin >> n;
                                          if (n>=0)
                                          {
                                              cout << n;
                                          }
                                          else
                                          {
                                              cout << n*-1;
                                          }
                                          return 0;
                                      }
                                  
                                  • -1
                                    @ 2023-6-13 19:51:36
                                    #include <bits/stdc++.h>
                                        using namespace std;
                                        int main()
                                        {
                                            int n;
                                            cin >> n;
                                            if (n>=0)
                                            {
                                                cout << n;
                                            }
                                            else
                                            {
                                                cout << n*-1;
                                            }
                                            return 0;
                                        }
                                    
                                    • -1
                                      @ 2022-8-29 11:35:16

                                      #include<bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; if (n >= 0){ cout << n; } else{ cout << 0 - n; } return 0; }**这道题挺简单的

                                      信息

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