114 条题解

  • -2
    @ 2022-5-19 20:26:54
    #include<iostream>//建议用iostream
    using namespace std;//使用标准命名空间
    int main(){//主函数
    	int a,b;
    	cin>>a>>b;
    	cout<<a+b;
    	return 0;
    }
    
    • -2
      @ 2022-5-8 20:16:04

      入门题,每个OIer入坑必做题

      不废话,直接上代码!

      C++:

      ```
      #include<iostream>
      using namespace std;
      int main(){
          int a,b;//定义变量
          cin>>a>>b;//输入
          cout<<a+b<<endl;//计算,输出
      }
      ```
      

      python3:

      # python3 要使用split函数,因为输入是一行两个数字,spilt函数可以把两个数字读取而不读取空格
      a=input().split() 
      print(int(a0])+int(a[1]))
      
      • -2
        @ 2022-5-7 10:36:51

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

        #include <bits/stdc++.h>
        using namespace std;
        
        int main()
        {
                int a,b;
                cin >> a >> b;
                cout << a + b;
        	
        	
        
        	return 0;
        }
        
        • -2
          @ 2022-3-22 12:54:54

          这道题目就是输出 a+b 的和就OK了! AC Code:

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

          注:我是新手,请多多请教!

          • @ 2022-6-8 9:14:48

            我不理解这种题解为什么会有人踩

          • @ 2022-7-25 16:29:54

            @因为没解释!

        • -2
          @ 2022-2-27 21:35:30
          #include <cstdio>
          using namespace std;
          int n, m;
          int main() {
              scanf("%d %d", &n, &m);
              printf("%d", n + m);
              return 0;
          }
          
          • -2
            @ 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;
            }
            
            • -2
              @ 2021-12-11 15:59:56

              一份十分简洁的 py3 代码:

              print(sum(map(int,input().split())))
              

              分析

              map(int,input().split())
              

              这句话将第一行输入数据读入,然后将其按空格分裂成 list。map 函数将这个 list 中的每个元素变成 int。

              print(sum(map(int,input().split())))
              

              接着,sum 函数求出了这个 list 内所有数的和,即 a+b。print 将其输出。

              • -2
                @ 2021-6-1 16:10:19

                这是一道很简单的入门题。
                可以直接写出代码:

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

                感谢您的阅读。

                • -3
                  @ 2023-8-31 18:44:38

                  这里估计大部分都是写了c++有一定基础的,那么我就用链表实现a+b问题吧

                  #include <iostream>
                  struct ListNode
                  {
                      int val;
                      ListNode *next;
                      ListNode(int x) : val(x), next(nullptr) {}
                  };
                  ListNode *addTwoNumbers(ListNode *l1, ListNode *l2)
                  {
                      ListNode *dummy = new ListNode(0);
                      ListNode *current = dummy;
                      int carry = 0;
                      while (l1 || l2 || carry)
                      {
                          int sum = carry;
                          if (l1)
                          {
                              sum += l1->val;
                              l1 = l1->next;
                          }
                          if (l2)
                          {
                              sum += l2->val;
                              l2 = l2->next;
                          }
                          carry = sum / 10;
                          sum = sum % 10;
                          current->next = new ListNode(sum);
                          current = current->next;
                      }
                      return dummy->next;
                  }
                  ListNode *createLinkedList(int arr[], int n)
                  {
                      if (n == 0)
                      {
                          return nullptr;
                      }
                      ListNode *head = new ListNode(arr[0]);
                      ListNode *current = head;
                      for (int i = 1; i < n; i++)
                      {
                          current->next = new ListNode(arr[i]);
                          current = current->next;
                      }
                      return head;
                  }
                  void printLinkedList(ListNode *head)
                  {
                      ListNode *current = head;
                      while (current)
                      {
                          std::cout << current->val << " ";
                          current = current->next;
                      }
                      std::cout << std::endl;
                  }
                  int main()
                  {
                      int arr1[1];
                      int arr2[1];
                      std::cin >> arr1[0];
                      std::cin >> arr2[0];
                      int n1 = sizeof(arr1) / sizeof(arr1[0]);
                      int n2 = sizeof(arr2) / sizeof(arr2[0]);
                      ListNode *l1 = createLinkedList(arr1, n1);
                      ListNode *l2 = createLinkedList(arr2, n2);
                      ListNode *sum = addTwoNumbers(l1, l2);
                      printLinkedList(sum);
                      return 0;
                  }
                  
                  • -3
                    @ 2023-8-2 16:18:31

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

                    • -3
                      @ 2023-8-2 16:17:15

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

                      • -3
                        @ 2023-3-12 19:21:44

                        #include<iostream> //头文件 using namespace std; //命名空间 int main(){ //主函数,程序从这里开始 int a,b; //定义变量 cin>>a>>b; //输入 cout<<a+b<<endl; //输出他们的和 return 0; //主函数需要返回0 }

                        • -3
                          @ 2022-11-1 22:27:02

                          Dijkstra+STL的优先队列优化。

                          #include <iostream>
                          #include <cstdio>
                          #include <cstdlib>
                          #include <cmath>
                          #include <cctype>
                          #include <climits>
                          #include <algorithm>
                          #include <map>
                          #include <queue>
                          #include <vector>
                          #include <ctime>
                          #include <string>
                          #include <cstring>
                          using namespace std;
                          const int N=405;
                          struct Edge {
                              int v,w;
                          };
                          vector<Edge> edge[N*N];
                          int n;
                          int dis[N*N];
                          bool vis[N*N];
                          struct cmp {
                              bool operator()(int a,int b) {
                                  return dis[a]>dis[b];
                              }
                          };
                          int Dijkstra(int start,int end)
                          {
                              priority_queue<int,vector<int>,cmp> dijQue;
                              memset(dis,-1,sizeof(dis));
                              memset(vis,0,sizeof(vis));
                              dijQue.push(start);
                              dis[start]=0;
                              while(!dijQue.empty()) {
                                  int u=dijQue.top();
                                  dijQue.pop();
                                  vis[u]=0;
                                  if(u==end)
                                      break;
                                  for(int i=0; i<edge[u].size(); i++) {
                                      int v=edge[u][i].v;
                                      if(dis[v]==-1 || dis[v]>dis[u]+edge[u][i].w) {
                                          dis[v]=dis[u]+edge[u][i].w;
                                          if(!vis[v]) {
                                              vis[v]=true;
                                              dijQue.push(v);
                                          }
                                      }
                                  }
                              }
                              return dis[end];
                          }
                          int main()
                          {
                              int a,b;
                              scanf("%d%d",&a,&b);
                              Edge Qpush;
                              
                              Qpush.v=1;
                              Qpush.w=a;
                              edge[0].push_back(Qpush);
                              
                              Qpush.v=2;
                              Qpush.w=b;
                              edge[1].push_back(Qpush);
                              
                              printf("%d",Dijkstra(0,2));
                              return 0;
                          }
                          
                          
                          
                          • -4
                            @ 2022-11-19 20:29:06

                            倒过来输出

                            • -4
                              @ 2022-4-6 15:30:41

                              c++新写法

                              #include<bits/stdc++.h>

                              using namespace std;

                              int a,b;

                              int main()

                              {

                              cin>>a>>b;

                              cout<<a+b;

                              return 0;

                              }

                              • -4
                                @ 2021-4-19 22:19:18

                                这是一道十分经典的题

                                重要的地方就在于输入输出

                                C++解法

                                #include <iostream> //引入输入输出流头文件
                                using namespace std;  
                                int mian()         //主函数
                                {
                                    int a, b;      //定义两个变量:a和b
                                    cin >> a >> b; //读入它们
                                    cout << a + b; //输出他们的和
                                    return 0;  
                                }
                                

                                C解法

                                #include <stdio.h>  //C语言的格式化输入输出头文件
                                int main()          //主函数
                                {
                                    int a, b;       //定义变量:a和b
                                    scanf("%d,%d", &a, &b);
                                    //这里运用了一个函数,他是scanf(格式化输入输出)
                                    //它的参数可以分成两大块,分别是格式和变量
                                    //格式可以使任意的,在格式字符串中要用%d来代替一个整数型变量
                                    //在后面的变量要和前面的代替符号(%d)一一对应,切记,变量前面需要加"&"(取址符)
                                    printf("%d", a + b);
                                    //这里又运用了一个和上面函数相对应的函数:printf(格式化输出)
                                    //同scanf,它前面是格式字符串,后面是对应的变量,但是,与scanf不同的是,后面的变量千万不要加"&"
                                    return 0;
                                }
                                

                                Pascal解法

                                var             {这是pascal特有的变量定义域}
                                 a, b:longint;  {定义两个长正型变量,这里注意不要用integer,会爆的哦}
                                begin           {pascal中程序开始关键字(也可以用于循环或分支中代表开始)}
                                 write(a + b); {输出他们的和}
                                end.            {pascal中程序结束的关键字(也可以用于循环或分支中代结束)}
                                

                                珍爱生命杜绝抄袭(我不会告诉你我加了防抄袭)

                                • @ 2022-1-4 16:26:49

                                  反作弊误导新手。。。不推荐

                              • -5
                                @ 2021-11-21 11:17:25

                                更简短的文言代码:

                                施「require('fs').readFileSync」於「「/dev/stdin」」。名之曰「入」。
                                施「(x=>x.toString().trim().split(/[ \t\n]/))」於「入」。昔之「入」者。今其是矣。
                                夫「入」之一。取一以施「parseInt」。名之曰「甲」。
                                夫「入」之二。取一以施「parseInt」。加「甲」以其。書之。
                                
                                • -6
                                  @ 2022-1-8 13:34:43

                                  水一篇题解哈哈哈哈哈

                                  声明:为了不错误引导新手上路,我会区分新手和神犇的解题方法(当然神犇不是我)

                                  新手请看这里:

                                  #include<iostream>
                                  using namespace std;
                                  int main()
                                  {
                                      int a,b;   //定义a,b两数,数据规模巨大的话用long long int也不是不可~
                                      cin>>a>>b;  //输入a,b
                                      cout<<a+b;  //输出a+b的结果,等同于int c=a+b; cout<<c;
                                      return 0;  //return 0好习惯
                                  }
                                  

                                  神犇请看这里:(高精度加法)

                                  先用字符串数组,以字符形式储存两个大数。再依次储存被加数,加数,和。之后再将字符数字转为四位一块的整数数字,逐块相加,并进位,最后计算和的块的总数即可。

                                  #include <bits/stdc++.h>
                                  #define N 200
                                  int Pow(int a, int b)
                                  {
                                      int i = 0, result = 1;
                                      for(i = 0; i < b; ++i)
                                      {
                                          result *= a;
                                      }
                                      return result;
                                  }
                                  int main()
                                  {
                                      char stra[N], strb[N];
                                      int i = 0, step = 4, carry = 0;
                                      int lengtha, lengthb, maxlength, resultsize;
                                      int numa[N], numb[N],numc[N];
                                      memset(numa, 0, sizeof(numa));
                                      memset(numb, 0, sizeof(numb));
                                      memset(numc, 0, sizeof(numc));
                                      scanf("%s%s", stra, strb);
                                      lengtha = strlen(stra);
                                      lengthb = strlen(strb);
                                      for(i = lengtha-1; i >= 0; --i)
                                      {
                                          numa[(lengtha-1-i)/step] += (stra[i]-'0')*Pow(10,(lengtha-1-i)%step);
                                      }
                                      for(i = lengthb-1; i >= 0; --i)
                                      {
                                          numb[(lengthb-1-i)/step] += (strb[i]-'0')*Pow(10,(lengthb-1-i)%step);
                                      }
                                      maxlength = lengtha > lengthb ? lengtha : lengthb;
                                      for(i = 0; i <= maxlength/step; ++i)
                                      {
                                          numc[i] = (numa[i] + numb[i])%Pow(10, step) + carry; 
                                          carry = (numa[i] + numb[i])/Pow(10, step); 
                                      }
                                      resultsize = numc[maxlength/step] > 0 ? maxlength/step : maxlength/step - 1;
                                      printf("%d", numc[resultsize]);
                                      for(i = resultsize-1; i >= 0; --i)
                                      {
                                          printf("%04d", numc[i]); 
                                      }
                                      printf("\n");
                                      return 0;
                                  }
                                  
                                  • -6
                                    @ 2021-11-9 16:40:50

                                    虽然这种简单题写个快读确实是大材小用, 但是有了快读,这个程序的主程序就可如python一般简洁

                                    因此就有了这篇题解,大家就当学快读的写法吧qwq

                                    #include <bits/stdc++.h>
                                    using namespace std;
                                    inline int read()
                                    {
                                        int X = 0; bool f = false; char ch = getchar();
                                        while (ch > '9' || ch < '0') {f |= ch == '-'; ch = getchar();}
                                        while (ch <= '9' && ch >= '0') {X = (X << 3) + (X << 1) + (ch ^ 48); ch = getchar();}
                                        return f ? -X : X;
                                    }
                                    inline void write(int X)
                                    {
                                        if (X == 0) {putchar('0'); return;}
                                        if (X < 0) {putchar('-'); X = -X;}
                                        short num[21], cnt = 0;
                                        while (X) {num[++cnt] = X % 10; X /= 10;}
                                        while (cnt) putchar(num[cnt--] ^ 48);
                                        return;
                                    }
                                    int main()
                                    {
                                        write(read() + read());
                                        return 0;
                                    }
                                    
                                    • -8
                                      @ 2022-8-21 14:37:57

                                      🚀️

                                      信息

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