88 条题解

  • 0
    @ 2024-4-14 21:46:40

    其实这道题非常简单,我们只需要用ans去求绝对值就好,上代码! #include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; cout << abs(n + 0); return 0; } 注意一定要用n+0;

    • 0
      @ 2024-3-16 14:33:11
      #include <iostream>
      using namespace std;
      int main()
      {
          int a;
          cin >> a;
          if(a < 0)
          {
              cout << -1 * a;
          }
          else
          {
              cout << a;
          }
          return 0;
      }
      
      • 0
        @ 2024-3-9 9:19:57

        不得不说这道题真的太水了

        1个函数直接解决

        上代码:

        codecode

        #include<iostream>
        #inckde<cmath>//头文件别忘加
        using namespace std;
        int main()
        {
            int a;//定义变量
            cin>>a;//输入
            cout<<abs(a);//输出绝对值
            return 0;//养成好习惯
        }
        
        • 0
          @ 2024-2-3 14:48:04

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

          • 0
            @ 2024-2-3 14:47:50

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

            • 0
              @ 2024-1-27 12:16:22

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

              • 0
                @ 2024-1-24 21:11:00
                #include <bits/stdc++.h>
                using namespace std;
                int n;
                int main()
                {
                    cin>>n;
                    if(n>=0)//如果是正数
                    {
                        cout<<n;//直接输出
                    }
                    else//如果是负数,要转化成正数
                    {
                        cout<<0-n;//例如:0-(-1)=1
                    }
                    //其实可以用abs函数
                    return 0;
                }
                
                • 0
                  @ 2024-1-2 21:57:13
                  #include <iostream>
                  using namespace std;
                  int main()
                  {
                      int n;
                      cin >> n;
                      if (n == 0)
                      {
                          cout << "0" << endl;
                      }
                      if (n > 0)
                      {
                          cout << n << endl;
                      }
                      if (n < 0)
                      {
                          cout << n*-1 << endl;
                      }
                      return 0;
                  }
                  
                  • 0
                    @ 2023-12-16 14:08:46
                    #include <bits/stdc++.h>
                    using namespace std;
                    int main()
                    {
                        int a;
                        cin>>a;
                        if(a<10)
                        {
                            cout<<"A";
                        }
                        else if((a>=10)&(a<20))
                        {
                            cout<<"B";
                        }
                        else if((a>=20)&(a<=40))
                        {
                            cout<<"C";
                        }
                        else if((a>=40)&(a<50))
                        {
                            cout<<"D";
                        }
                        else
                        {
                            cout<<"E";
                        }
                        return 0;
                    }
                    
                    • 0
                      @ 2023-11-19 21:14:41
                      #include <bits/stdc++.h>
                          using namespace std;
                          int main()
                          {
                              int n;
                              cin >> n;
                              if (n>=0)
                              {
                                  cout << n;
                              }
                              else
                              {
                                  cout << n*-1;
                        //注意!不能是cout << -n或cout << "-" << n;
                              }
                              return 0;
                          }
                      

                      点个赞吧

                      • 0
                        @ 2023-11-12 10:25:17

                        #include using namespace std; int main() { int a; cin >> a; if (a>=0) { cout << a; } if (a<0) { cout << -a; } return 0; }

                        
                        
                        
                        
                        • 0
                          @ 2023-11-12 10:21:01
                          #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
                            @ 2023-10-4 22:56:52
                            #include <bits/stdc++.h>
                            using namespace std;
                            int n;
                            int main()
                            {
                                cin>>n;
                                if (n>0)
                                {
                                    cout<<n;
                                }
                                else
                                {
                                    cout<<-n;
                                }
                                return 0;
                            }
                            
                            • 0
                              @ 2023-9-28 22:48:47

                              此题可以用头文件stdlib.h中的abs函数解题,代码如下 #include <bits/stdc++.h>//可以用iostream, 如果要用万能头文件,可以删除第二行 #include <stdlib.h> using namespace std; int main(){ int a; cin >> a; cout << abs (a); return 0; }

                              • 0
                                @ 2023-8-27 22:44:13
                                #include <bits/stdc++.h>//万能开头
                                using namespace std;
                                int n;//定义变量
                                int main()
                                {
                                    cin>>n;//输入变量
                                    if(n>=0)
                                    {
                                        cout<<n;//如果大于等于0,直接输出它
                                    }
                                    else
                                    {
                                        cout<<-n;//否则输出负的n(负负得正)
                                    }
                                    return 0;
                                }
                                
                                //或者
                                
                                #include <bits/stdc++.h>//万能开头
                                using namespace std;
                                int n;//定义变量
                                int main()
                                {
                                    cin >> n;//输入变量
                                    cout << abs(n);//绝对值函数abs()
                                    return 0;
                                }
                                
                                
                                
                                //一手交赞,一手交货(代码)
                                
                                
                                
                                
                                
                                //核桃hetao1609095编程
                                //水印
                                
                                • 0
                                  @ 2023-8-6 13:39:18
                                  #include <iostream>
                                  nsing namespace std;
                                  int main()
                                  {
                                      int n;
                                      cin >> n;
                                      if (n >= 0)
                                      {
                                          cout << n;
                                      }
                                      if (n < 0)
                                      {
                                          cout << n-n*2;
                                      }
                                      return 0;
                                  }
                                  请问我这道题哪错了?😕 ❤️ 
                                  
                                  • @ 2023-8-9 22:21:55

                                    第二行开头是using,你写成nsing 了

                                • 0
                                  @ 2023-8-6 13:30:00

                                  请先点赞,后看代码!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

                                • 0
                                  @ 2023-8-1 10:29:48
                                  #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
                                    @ 2023-7-7 20:17:29

                                    这么简单,还不快去试试? image

                                    • 0
                                      @ 2023-5-2 17:17:23

                                      还挺简单的 #include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; cout<<abs(n)<<endl; return 0; }

                                      信息

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