171 条题解

  • -1
    @ 2024-10-10 20:24:54
    #include<bits/stdc++.h>
    using namespace std;
    int main(){
        long long a,b;
        cin >> a >> b;
        cout << a+b;
        return 0;
    }
    • -1
      @ 2024-9-17 7:56:13

      终于能做一道a+b这么难的题啦! code:

      #include<bits/stdc++.h> //万能头文件
      using namespace std; //命名空间
      long long add(int a,int b){//加法函数(int要爆)
      cin>>a>>b;
      for(int i=a;i<=b;i++){//循环相加(也可以地柜)
      i++;
      }
      int main(){
      int a,b;
      add(a,b);
      return 0;
      }
      

      finish

      • -1
        @ 2024-9-11 16:53:33

        分享一种利用 C++ 特性的厌氧解法

        警告:这个做法严重依赖于编译器、操作系统等的特殊性质,极不稳定。

        #include <bits/stdc++.h>
        using namespace std;
        
        void A() {
            int a, b;
            scanf("%d %d", &a, &b);
        }
        void B() {
            int a, b;
            printf("%d\n", a + b);
        }
        
        int main() {
            A(), B();
            return 0;
        }
        

        不开 O2 可 AC,开 O2 就 WA。

      • -1
        @ 2024-9-8 18:02:23

        这很简单吧?

        #include <iostream>
        using namespace std;
        int main(){
            int a,b;
            while(cin>>a>>b){
                cout<<a+b;
            }
            return 0;
        }
        • -1
          @ 2024-8-28 20:42:40

          我当初看见这道题的时候感觉很难,但是我想了亿下……

          s = input()
          a = s[:s.index(" ")]
          b = s[s.index(" "):]
          print(a + b)
          
          • -1
            @ 2024-8-28 8:53:53
            #include <bits/stdc++.h>
            using namespace std;
            typedef long long ll;
            
            int main() {
            //	freopen(".in","r",stdin);
            //	freopen(".out","w",stdout);
            	int a,b;
            	cin>>a>>b;
            	cout<<a+b;
            	return 0;
            }
            
            • -1
              @ 2024-7-31 20:47:03

              所以写题解会加RP吗?(每日一问)

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

              以至于我为什么要用long long我也不知道

              注释: (1):万能头文件,几乎包含所有头文件( (2):换行,比endl快一点

              • -1
                @ 2024-7-2 8:21:26

                第一次写题解😄

                #include <bits/stdc++.h>//万能头
                using namespace std;
                int main() {
                int a, b;//定义
                cin >> a >> b;//输入
                cout << a + b;//输出
                return 0;//返回
                }
                
                • -1
                  @ 2024-7-1 20:24:17
                  #include<bits/stdc++.h>
                   using namespace std; 
                  int main()
                  { 
                      int a, b; 
                      cin>>a>>b; 
                      cout<<a+b; 
                      return 0;
                  }
                  
                  • -1
                    @ 2024-6-9 21:34:09
                    #include <bits/stdc++.h>
                    using namespace std;
                    const int N = 1e4 + 15, M = 2e5 + 10;
                    
                    vector<int> edge[N];
                    int h[N], e[M], ne[M], idx, p[N];
                    int in[N];
                    int n, m;
                    void add(int a, int b) {
                        e[idx] = b, ne[idx] = h[a], h[a] = idx ++ ;
                        in[b]++;
                    }
                    
                    int dfn[N], low[N], tot = 0;
                    stack<int> stk;
                    bool st[N];
                    int sz[N], scc[N], color;
                    
                    void tarjan(int u) {
                        dfn[u] = low[u] = ++tot;
                        stk.push(u); st[u] = true;
                        for (int v : edge[u]) {
                            if (!dfn[v]) tarjan(v), low[u] = min(low[u], low[v]);
                            else if (st[v]) low[u] = min(low[u], dfn[v]);
                        }
                        if (dfn[u] == low[u]) {
                            ++color;
                            while (stk.top() != u) {
                                scc[stk.top()] = color;
                                st[stk.top()] = false; stk.pop();
                            }
                            scc[stk.top()] = color;
                            st[stk.top()] = false; stk.pop();
                        }
                    }
                    
                    queue<int> q;
                    int dp[N];
                    void topsort() {
                        for (int i = 1; i <= color; i++) {
                            dp[i] = sz[i];
                            if (in[i] == 0) q.push(i);
                        }
                        while (q.size()) {
                            int u = q.front(); q.pop();
                            for (int i = h[u]; ~i; i = ne[i]) {
                                int v = e[i];
                                dp[v] = max(dp[v], dp[u] + sz[v]); in[v]--;
                                if (in[v] == 0) q.push(v);
                            }
                        }
                        int ans = 0;
                        for (int i = 1; i <= color; i++) ans = max(ans, dp[i]);
                        printf("%d\n", ans);
                    }
                    
                    int main() {
                        memset(h, -1, sizeof h);
                        n = 2, m = 1;
                        for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
                        while (m--) {
                            int a = 1, b = 2;
                            edge[a].push_back(b);
                        }
                        for (int i = 1; i <= n; i++)
                            if (!dfn[i]) tarjan(i);
                        for (int i = 1; i <= n; i++) {
                            sz[scc[i]] += p[i];
                            for (int j : edge[i])
                                if (scc[i] != scc[j]) add(scc[i], scc[j]);
                        }
                        topsort();
                        return 0;
                    }
                    

                    转自AcWing@Conan15

                    • -1
                      @ 2024-6-8 19:44:05

                      函数做法:

                      #include<bits/stdc++.h>
                      using namespace std;
                      int add(int a, int b){
                      	return a + b;
                      }
                      
                      int main(){
                      	int a, b;
                      	cin >> a >> b;
                      	cout << add(a, b);
                      }
                      
                      • -1
                        @ 2024-5-31 10:42:13

                        按照题目计算 a+ba+b 就可以了。

                        #include<bits/stdc++.h>//万能头
                        using namespace std;//命名空间
                        int main(){//主函数
                            int a,b;//int类型变量
                            cin >> a >> b;//读入
                            cout << a+b;//输出
                            return 0;//结束
                        }
                        
                        • -1
                          @ 2024-5-19 21:03:56

                          A+B作为一道基础题,思维也很简单 看代码:

                          #include <bits/stdc++.h>
                          #define endl '\n'
                          #define int long long
                          
                          using namespace std;
                          
                          signed main()
                          {
                          	int a, b;
                          	cin >> a >> b;
                          	cout << a + b; 
                          	
                          	return 0;
                          }
                          
                          • -1
                            @ 2024-5-7 19:21:02

                            还是要点水平

                            import java.util.Scanner;
                            
                            public class Main{
                            
                                public static void main(String[] args) {
                            
                                    Scanner scanner = new Scanner(System.in);
                            
                                    System.out.println(scanner.nextInt() + scanner.nextInt());
                            
                                    scanner.close();
                                }
                            }
                            
                            • -1
                              @ 2024-4-21 10:05:30

                              A+B问题居然没有高精度题解,发一篇吧!

                              #include <bits/stdc++.h> using namespace std; const int maxn=250; char sa[maxn],sb[maxn];//定义两个字符串 int a[maxn],b[maxn],c[maxn];//a,b位数字,c进位 int main() { scanf ("%d",sa); scanf ("%d",sb); memset (c,0,sizeof(c));//初始化赋值为0 int la=strlen (sa);//取字符串长度 int lb=strlen (sb); for (int i=0;i<la;i++) a[la-i-1]=sa[i]-'0'; for (int i=0;i<lb;i++) b[lb-i-1]=sb[i]-'0';//将两个字符串类型的数转换成整数 int lc=la>lb?la:lb;//三目运算符,取两个数字中数位最长的数字的数位 for (int i=0;i<lc;i++) { c[i] += a[i]+b[i];//加法运算 if (c[i]>=10) { c[i+1]=a[i]/10; c[i]=c[i]%10;//进位 } } if (c[lc]>0) lc++; int cnt=lc-1; while (c[cnt]==0) cnt--; for (int i=cnt;i>=0;i--) printf ("%d",c[i]); return 0; }

                              • -1
                                @ 2024-4-14 8:31:48

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

                                • -1
                                  @ 2024-4-14 8:31:46

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

                                  • -1
                                    @ 2024-4-6 11:58:55

                                    经典的 a+ba+b

                                    • -1
                                      @ 2024-4-5 20:01:38
                                      #include
                                      using namespace std;
                                      
                                      struct Node
                                      {
                                      int data;
                                      Node *prev;
                                      Node *next;
                                      Node(int val) : data(val), prev(nullptr), next(nullptr) {}
                                      };
                                      
                                      Node *createList(int num)
                                      {
                                      Node *head = nullptr;
                                      Node *tail = nullptr;
                                      while (num > 0)
                                      {
                                      int digit = num % 10;
                                      Node *newNode = new Node(digit);
                                      if (head == nullptr)
                                      {
                                      head = newNode;
                                      tail = newNode;
                                      }
                                      else
                                      {
                                      newNode->next = head;
                                      head->prev = newNode;
                                      head = newNode;
                                      }
                                      num /= 10;
                                      }
                                      return head;
                                      }
                                      
                                      Node *addTwoNumbers(Node *num1, Node *num2)
                                      {
                                      Node *result = nullptr;
                                      Node *current = nullptr;
                                      int carry = 0;
                                      

                                      while (num1 != nullptr || num2 != nullptr || carry != 0) { int sum = carry;

                                      if (num1 != nullptr)
                                      {
                                          sum += num1->data;
                                          num1 = num1->next;
                                      }
                                      
                                      if (num2 != nullptr)
                                      {
                                          sum += num2->data;
                                          num2 = num2->next;
                                      }
                                      
                                      carry = sum / 10;
                                      sum %= 10;
                                      
                                      Node *newNode = new Node(sum);
                                      
                                      if (result == nullptr)
                                      {
                                          result = newNode;
                                          current = newNode;
                                      }
                                      else
                                      {
                                          current->prev = newNode;
                                          newNode->next = current;
                                          current = newNode;
                                      }
                                      

                                      }

                                      return result;

                                      }
                                      
                                      void printList(Node *head)
                                      {
                                      if (head == nullptr)
                                      {
                                      cout << "Empty list" << endl;
                                      return;
                                      }
                                      

                                      while (head != nullptr) { cout << head->data; head = head->next; } cout << endl;

                                      }
                                      
                                      void deleteList(Node *head)
                                      {
                                      while (head != nullptr)
                                      {
                                      Node *temp = head;
                                      head = head->next;
                                      delete temp;
                                      }
                                      }
                                      
                                      int main()
                                      {
                                      int num1 = 12345;
                                      int num2 = 6789;
                                      

                                      Node *list1 = createList(num1); Node *list2 = createList(num2);

                                      cout << "Number 1: "; printList(list1);

                                      cout << "Number 2: "; printList(list2);

                                      Node *sumList = addTwoNumbers(list1, list2);

                                      cout << "Sum: "; printList(sumList);

                                      deleteList(list1); deleteList(list2); deleteList(sumList);

                                      return 0;

                                      }
                                      
                                      

                                      信息

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