137 条题解

  • -1
    @ 2023-9-16 12:19:29
    #include <bits/stdc++.h>
    
    using namespace std;
    
    int main(){
        int a;
        int b;
        cin>>a>>b;
        printf("%d",a+b);
        return 0;
    
    }
    
    • -1
      @ 2023-9-15 20:33:08

      何不试一试这种C++代码呢?

      #include <iostream>
      #include <string>
      
      // 定义 A+B 的函数
      std::string add(std::string num1, std::string num2) {
          // 将两个数字字符串转换为数字数组
          int len1 = num1.length();
          int len2 = num2.length();
          int maxLen = std::max(len1, len2);
          int* arr1 = new int[maxLen];
          int* arr2 = new int[maxLen];
          for (int i = 0; i < maxLen; i++) {
              if (i < len1) {
                  arr1[i] = num1[len1 - i - 1] - '0';
              } else {
                  arr1[i] = 0;
              }
              if (i < len2) {
                  arr2[i] = num2[len2 - i - 1] - '0';
              } else {
                  arr2[i] = 0;
              }
          }
      
          // 进行加法运算
          int carry = 0;
          std::string result = "";
          for (int i = 0; i < maxLen; i++) {
              int sum = arr1[i] + arr2[i] + carry;
              carry = sum / 10;
              result = std::to_string(sum % 10) + result;
          }
          if (carry > 0) {
              result = std::to_string(carry) + result;
          }
      
          delete[] arr1;
          delete[] arr2;
      
          return result;
      }
      
      int main() {
          // 读取输入的两个数字
          std::string num1, num2;
          std::cout << "请输入两个数字:" << std::endl;
          std::cin >> num1 >> num2;
      
          // 计算并输出结果
          std::string sum = add(num1, num2);
          std::cout << "结果为:" << sum << std::endl;
      
          return 0;
      }
      

      但愿这种代码不会出现TLE或者是MLE 这个代码使用了字符串来表示大数,通过将字符串转换为数字数组,然后进行逐位相加的方式来实现 A+B 的功能。由于使用了字符串和动态数组,代码量较大。但是在实际应用中,这种方式并不是最高效的解决方案。在实际情况下,我们可以使用更简洁和高效的算法来解决这个问题。


      我们可以用更简洁的方法做这道题

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

      上面的代码是进行变量a和b直接相加的代码吗,这种也许就是标准代码。

      好了,这道题的题解到此为止,走过路过,不要错过,点点赞吧~~~么么哒😗🥰

      • -1
        @ 2023-9-5 17:08:14
        #include<iostream> //头文件
        using namespace std; //命名空间
        int main(){ //主函数,程序从这里开始
            int a,b; //定义变量
            cin>>a>>b; //输入
            cout<<a+b<<endl; //输出他们的和
            return 0; //主函数需要返回0
        }
        
        • -1
          @ 2023-8-12 15:01:05

          Python 压行技巧,详细讲一讲:

          1. split 函数,可以将字符串按一定分隔符分割,放在一个 list 中。例如,s'abc.abcd',那么 s.split ('.') 就是 ['abc', 'abcd'],如果没有参数,默认为 ' '
          2. map 函数,可以将一个序列依次进行某个操作的最终序列。例如,a[1, 1, 4, 5, 1, 4]func 函数定义如下:
            def func (int x):
                return x + 1
            
            那么 map (func, a) 就是 [2, 2, 5, 6, 2, 5]
          3. sum 函数,可以求一个序列的和。例如,按照上面的 a,那么 sum (a) 就是 16

          最终代码(注释参考样例一,不含注释一行):

           print(sum(map(int,input().split())))
          #print(sum(map(int, '1 2' .split())))
          #print(sum(map(int,   ['1', '2']  )))
          #print(sum(         [1, 2]        )))
          #print(             2               )
          
          • -1
            @ 2023-6-10 19:25:23

            本蒟蒻第一次发题解:

            #include <bits/stdc++.h> //头文件
            using namespace std;//命名空间
            int a,b; //定义变量
            int main() { //主函数,程序从这里开始 
                cin>>a>>b; //输入
                cout<<a+b<<endl; //输出他们的和
                return 0; //主函数需要返回0
            }
            
            • -1
              @ 2023-3-19 15:21:32
              #include <bits/stdc++.h>
              #define int long long
              using namespace std;
              signed main() {
                  ios::sync_with_stdio(false);
                  cin.tie(nullptr);
                  int a, b; cin >> a >> b;
                  cout << a + b << '\n';
                  return 0;
              }
              
              • -1
                @ 2023-3-3 18:49:59

                这题很简单,输入 aa 和 bb,然后输出他们的和即可。

                #include <stdio.h>
                
                int main()
                {
                    int a,b;
                    scanf("%d%d",&a,&b);
                    printf("%d\n", a+b);
                    return 0;
                }
                
                • -1
                  @ 2022-12-29 10:55:08

                  非常简单的一道题,代码:

                  var a,b:longint;
                  begin
                      readln(a,b);
                      write(a+b);
                  end.
                  

                  注意pascal用integer会爆掉。

                  • -1
                    @ 2022-12-3 11:34:28
                    #include<bits/stdc++.h>
                    using namespace std;
                    int main(){
                         int a,b;
                         scanf("%d%d",&a,&b);
                         return !printf("%d",a+b);
                    }
                    
                    • -1
                      @ 2022-4-11 7:50:21
                      #include<bits/stdc++.h>
                      using namespace std;
                      int main(){
                        int a,b;
                        cin>>a>>b;
                        cout<<a+b;
                        return 0;
                      }
                      
                      • -1
                        @ 2022-3-26 0:01:54
                        //新手可看此贴
                        #include<bits/stdc++.h>
                        using namespace std;
                        long long a,b;//定义变量a,b
                        int main(){
                            cin>>a>>b;//将a,b输入
                            cout<<a+b;//将a,b的和输出
                            return 0;//主函数返回值为0
                        }
                        
                        • -1
                          @ 2022-2-27 14:12:10
                          #include <bits/stdc++.h>
                          #include <cstdio>
                          using namespace std;
                          
                          int main()
                          {
                              long long a, b;
                              
                              scanf("%d%d", &a, &b);
                          
                              printf("%d", a + b);
                          
                              return 0;
                          }
                          
                          • -1
                            @ 2021-10-23 14:47:13
                            #include<iostream> 
                            using namespace std; 
                            int main(){ 
                                int a,b; 
                                cin>>a>>b; 
                                cout<<a+b<<endl;
                                return 0; 
                            }
                            
                            • -1
                              @ 2021-10-5 9:20:35

                              水个 py 的吧。

                              a=input().split()
                              # 用 split() 切片
                              print(int(a[0])+int(a[1]))
                              # 先转 int 型再相加
                              
                              • -1
                                @ 2021-4-24 8:53:55

                                我来写一个Python题解。

                                a,b=map(int,input().split())#读入变量a、b,以空格隔开,并转为整型(int)
                                print(a+b)#输出a+b的值
                                

                                不得不说Python是真心简单

                                • -2
                                  @ 2024-1-15 10:17:25

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

                                  • -2
                                    @ 2023-8-31 23:04:01

                                    C++ 式普通写法

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

                                    高精度

                                    #include<iostream>
                                    
                                    using namespace std;
                                    
                                    const int MAXN = 1e5 + 10;
                                    
                                    long long r;
                                    int c;
                                    char op;
                                    
                                    struct bigint{
                                      long long len,sz[MAXN] = {0};
                                    
                                      long long &operator [] (long long a){
                                        return sz[a];
                                      }
                                    
                                      void input(){
                                        string s;
                                        cin >> s;
                                        len = s.size();
                                        for (int i = 0; i < len; i++){
                                          sz[i] = s[len - i - 1] - '0';
                                        }
                                      }
                                    
                                      void output(){
                                        for (; len - 1 > 0 && !sz[len - 1]; len--){
                                        }
                                    
                                        for (int i = len - 1; i >= 0; i--){
                                          cout << sz[i];
                                        }
                                        cout << '\n';
                                      }
                                      bigint operator + (const bigint &b){
                                        bigint c;
                                        c.len = max(len,b.len) + 1;
                                        for (int i = 0; i < c.len; i++){
                                          c[i] = sz[i] + b.sz[i];
                                        }
                                    
                                        for (int i = 0; i < c.len - 1; i++){
                                          c[i + 1] += c[i] / 10,c[i] %= 10;
                                        }
                                        return c;
                                      }
                                    }a,b,ans;
                                    
                                    int main(){
                                      a.input(),b.input();
                                      ans = a + b;
                                      ans.output();
                                      return 0;
                                    }
                                    
                                    • -2
                                      @ 2023-7-18 18:53:00
                                      #include <bits/stdc++.h>
                                      using namespace std;
                                      int main() {
                                          //以下三行为输入输出超大数据时标准输入输出流的加速
                                          ios::sync_with_stdio(false);
                                          cin.tie(0);
                                          cout.tie(0);
                                          long long a,b;
                                          cin>>a>>b;
                                          cout<<a+b<<endl;
                                          return 0;
                                      }
                                      
                                      • -2
                                        @ 2023-6-4 21:59:03
                                        **#include** **<**bits**/**stdc**++.**h**>**
                                         **using** **namespace** **std**;
                                         **/\***
                                         **  **思路:将字符串s所有拆分的可能性都尝试一下
                                         **  **打擂台求出最小的素数
                                         ** **\*/
                                         
                                         //素数判断
                                         **bool** **sushu**(**int** **n**)** **{
                                         **    **for** **(**int** **i** **=** **2**;** **i** **<=** **sqrt**(**n**);** **i**++)** **{
                                         **        **if** **(**n** **%** **i** **==** **0**)** **{
                                         **            **return** **false**;**
                                         **        **}
                                         **    **}
                                         **    **if** **(**n** **<=** **1**)** **return** **false**;**
                                         **    **return** **true**;**
                                         }
                                         **int** **main**()** **{
                                         **    **string** **s**,** **s1**,** **s2**;**
                                         **    **int** **i**,** **mi** **=** **INT\_MAX**;** **//mi存储最小的素数
                                         **    **cin** **>>** **s**;**
                                         **    **int** **x**,** **y**;
                                         **    **/\*长度为s.size()的字符串,拆s.size()-1次
                                         **      **12345
                                         **      **i=0** **1** **2345** **s.substr(0,1)**  **s.substr(1)
                                         **      **i=1** **12** **345** **s.substr(0,2)**  **s.substr(2)
                                         **     **\*/
                                         **    **//循环拆段的次数
                                         **    **for** **(**i** **=** **0**;** **i** **<** **s**.**size**()** **-** **1**;** **i**++)** **{**
                                         **        **s1** **=** **s**.**substr**(**0**,** **i** **+** **1**);
                                         **        **s2** **=** **s**.**substr**(**i** **+** **1**);**
                                         **        **//cout<<s1<<"** **"<<s2<<endl;
                                         **        **x** **=** **atoi**(**s1**.**c\_str**());**
                                         **        **y** **=** **atoi**(**s2**.**c\_str**());**
                                         
                                         **        **if** **(**sushu**(**x** **+** **y**)** **&&** **x** **+** **y** **<** **mi**)** **mi** **=** **x** **+** **y**;
                                         **    **}
                                         **    **if** **(**mi** **==** **INT\_MAX**)** **cout** **<<** **-**1**;
                                         **    **else** **cout** **<<** **mi**;**
                                         **    **return** **0**;**
                                         }
                                        
                                        • -2
                                          @ 2023-4-15 16:04:08
                                          #include<iostream>
                                          using namespace std;
                                          int a, b;
                                          int main() {
                                              cin >> a >> b;
                                              cout << a + b << endl;
                                              return 0; 
                                          }
                                          

                                          信息

                                          ID
                                          56
                                          时间
                                          1000ms
                                          内存
                                          1024MiB
                                          难度
                                          1
                                          标签
                                          递交数
                                          8392
                                          已通过
                                          3776
                                          上传者