145 条题解

  • 0
    @ 2023-10-3 19:28:15

    极简版:

    #include <iostream>
    using namespace std;
    int main(){int a,b;cin>>a>>b;cout<<a+b;return 0;}
    
    • @ 2024-1-18 21:00:16

      还有更简洁的

      # include <bits/stdc++.h>
      using namespace std;int main() {int a, b;scanf("%d%d", &a, &b);printf("%d", a + b);return 0;}
      
    • @ 2024-8-19 21:00:04

      @ @ @ 可以把using namespace std语句去掉,因为这是C

  • 0
    @ 2023-10-2 13:53:11
    #include<bits/stdc++.h> //引入头文件
    using namespace std; //设置namespace
    
    int main(){ //主函数
        int a,b; //定义变量
        cin >>a >> b; //输入
        cout << a+b; //输出
        return 0; //结束代码
    }
    
    • 0
      @ 2023-9-24 11:48:26

      A+B Problem

      题解+思路

      题解

      #include <iostream>
      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;
      }
      

      思路

      1. 首先,定义一个双向链表的节点结构体,包含一个整数值和两个指针,分别指向前一个节点和后一个节点。
      2. 创建两个双向链表,分别表示要相加的两个数字。可以通过遍历输入的整数,从个位开始,逐个创建节点并将其插入链表中。
      3. 定义一个变量来表示进位,初始值为0。
      4. 从链表的最后一个节点开始,逐位相加,并将结果存储在新的链表中。具体步骤如下: - 从两个链表的最后一个节点开始,分别取出对应的值,并加上进位。 - 将相加的结果对10取模得到当前位的值,同时更新进位为相加结果除以10的商。 - 创建一个新的节点,将当前位的值存储在该节点中,并将该节点插入到结果链表的头部。 - 分别将两个链表的指针指向上一个节点,继续下一位的相加操作。 - 如果其中一个链表已经遍历完,但另一个链表还有剩余位数,则将剩余位数与进位相加,并将结果插入到结果链表中
      5. 最后,得到的结果链表即为相加后的结果。
      • 0
        @ 2022-12-22 10:49:25
        #include<iostream>
        using namespace std;
        int main()
        {
            int a,b;
            cin>>a>>b;
            cout<<a+b;
        }
        
        • @ 2024-8-19 20:58:48

          建议在cout<<a+b;后面换行并增加return 0;语句

      • 0
        @ 2021-4-24 8:53:55

        我来写一个Python题解。

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

        不得不说Python是真心简单

        • -1
          @ 2024-8-28 19:51:16
          #include <bits/stdc++.h>
          using namespace std;
          int main()
          {
          	long long a,b;
          	cin>>a>>b;
          	cout<<a+b;
          	return 0;
          }
          
          
          • -1
            @ 2024-8-20 13:25:47
            #include <bits/stdc++.h>
            using namespace std;
            int main()
            {
                int a,b;
                cin>>a>>b;
                cout<<a+b;
                return 0;
            }
            
            • -1
              @ 2024-8-20 11:17:28

              1

              • -1
                @ 2024-8-19 18:23:12

                A+B Problem 题解

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

                推荐题目

                • -1
                  @ 2024-8-19 16:20:15

                  本蒟蒻啥都不会,只能贡献一份小小的码风优良的代码```language

                  #include <iostream>
                  using namespace std;
                  
                  const int MAX = 1000;
                  
                  void change(const string &a1, int a[], int len)
                  {
                  	for (int i = 0; i < len; i++)
                  	{
                  		a[i] = a1[len - i - 1] - '0';
                  	}
                  }
                  
                  int main()
                  {
                  	string a1, b1;
                  	cin >> a1 >> b1;
                  	int lena = a1.size(), lenb = b1.size();
                  	int a[MAX] = {}, b[MAX] = {}, c[MAX] = {}, cf = 0;
                  	change(a1, a, lena);
                  	change(b1, b, lenb);
                  	int lenc = lena;
                  	if (lenb > lena)
                  	{
                  		lenc = lenb;
                  	}
                  	for (int i = 0; i <= lenc; i++)
                  	{
                  		c[i] = a[i] + b[i] + cf;
                  		if (c[i] >= 10)
                  		{
                  			cf = 1;
                  			c[i] -= 10;
                  		}
                  		else
                  		{
                  			cf = 0;
                  		}
                  	}
                  	int i = lenc;
                  	if (c[i] == 0)
                  	{
                  		i--;
                  	}
                  	for (i; i >= 0; i--)
                  	{
                  		cout << c[i];
                  	}
                  	return 0;
                  }
                  • -1
                    @ 2024-8-19 13:00:40
                    C++:C++:
                    #include<bits/stdc++.h> //头文件
                    using namespace std;//命名空间
                    int main(){//主函数,程序从这里开始
                        //signed main也行
                        long long a,b;
                        //用long long类型的变量进行存储因为数值范围是10^6,int存不下
                        cin>>a>>b;
                        /*
                          这里可以替换为:
                          scanf("%lld%lld",&a,&b);
                        */
                        long long ans=a+b;
                        cout<<ans<<endl;
                        /*
                          这里可以替换为:
                          printf("%lld",ans);
                        */
                        return 0;//一定要写,不然RE
                    }
                    
                    • -1
                      @ 2024-8-3 10:04:01

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

                      • -1
                        @ 2024-7-15 22:58:04
                        终于可以写一份A+B这么难的题的题解了。
                        咦?竟然没有人写LCT的题解?
                        Link-Cut Tree 会很伤心的!
                        ORZ为了不让LCT伤心于是我来一份LCT的A+B题解吧!
                        送上代码:
                        
                        #include<iostream>
                        #include<cstring>
                        #include<cstdio>
                        #include<cstring>
                        using namespace std;
                        struct node 
                        {
                            int data,rev,sum;
                            node *son[2],*pre;
                            bool judge();
                            bool isroot();
                            void pushdown();
                            void update();
                            void setson(node *child,int lr);
                        }lct[233];
                        int top,a,b;
                        node *getnew(int x)
                        {
                            node *now=lct+ ++top;
                            now->data=x;
                            now->pre=now->son[1]=now->son[0]=lct;
                            now->sum=0;
                            now->rev=0;
                            return now;
                        }
                        bool node::judge(){return pre->son[1]==this;}
                        bool node::isroot()
                        {
                            if(pre==lct)return true;
                            return !(pre->son[1]==this||pre->son[0]==this);
                        }
                        void node::pushdown()
                        {
                            if(this==lct||!rev)return;
                            swap(son[0],son[1]);
                            son[0]->rev^=1;
                            son[1]->rev^=1;
                            rev=0;
                        }
                        void node::update(){sum=son[1]->sum+son[0]->sum+data;}
                        void node::setson(node *child,int lr)
                        {
                            this->pushdown();
                            child->pre=this;
                            son[lr]=child;
                            this->update();
                        }
                        void rotate(node *now)
                        {
                            node *father=now->pre,*grandfa=father->pre;
                            if(!father->isroot()) grandfa->pushdown();
                            father->pushdown();now->pushdown();
                            int lr=now->judge();
                            father->setson(now->son[lr^1],lr);
                            if(father->isroot()) now->pre=grandfa;
                            else grandfa->setson(now,father->judge());
                            now->setson(father,lr^1);
                            father->update();now->update();
                            if(grandfa!=lct) grandfa->update();
                        }
                        void splay(node *now)
                        {
                            if(now->isroot())return;
                            for(;!now->isroot();rotate(now))
                            if(!now->pre->isroot())
                            now->judge()==now->pre->judge()?rotate(now->pre):rotate(now);
                        }
                        node *access(node *now)
                        {
                            node *last=lct;
                            for(;now!=lct;last=now,now=now->pre)
                            {
                                splay(now);
                                now->setson(last,1);
                            }
                            return last;
                        }
                        void changeroot(node *now)
                        {
                            access(now)->rev^=1;
                            splay(now);
                        }
                        void connect(node *x,node *y)
                        {
                            changeroot(x);
                            x->pre=y;
                            access(x);
                        }
                        void cut(node *x,node *y)
                        {
                            changeroot(x);
                            access(y);
                            splay(x);
                            x->pushdown();
                            x->son[1]=y->pre=lct;
                            x->update();
                        }
                        int query(node *x,node *y)
                        {
                            changeroot(x);
                            node *now=access(y);
                            return now->sum;
                        }
                        int main()
                        {
                            scanf("%d%d",&a,&b);
                            node *A=getnew(a);
                            node *B=getnew(b);
                            //连边 Link
                                connect(A,B);
                            //断边 Cut
                                cut(A,B);
                            //再连边orz Link again
                                connect(A,B);
                            printf("%d\n",query(A,B)); 
                            return 0;
                        }
                        

                        本蒟蒻第一次写题解,请原谅

                        • @ 2024-7-25 19:06:25

                          又一个抄洛谷的🤣👉

                      • -1
                        @ 2024-7-15 22:54:04
                        
                        #include<iostream>//头文件
                        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();
                                        }
                                    }
                                    

                                    信息

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