114 条题解

  • 0
    @ 2024-3-17 11:26:22

    #include<bits/stdc++.h> using namespace std; long long m,n; int main(){ cin>>n>>m; cout<<n+m<<endl; }

    • 0
      @ 2024-2-16 9:02:02

      #include <bits/stdc++.h> using namespace std;
      int main() {
      int a, b;
      cin >> a >> b;
      cout << a + b;
      return 0;
      }
      兄啊,这是给若至做的罢(恼

      • 0
        @ 2024-2-5 21:13:26

        这道题想必不用多说了吧,直接附上代码

        
        

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

        
        
        • @ 2024-2-14 19:47:31

          e……你可以复制代码时直接复制,等会如果没有再写仨 `

      • 0
        @ 2024-1-28 14:00:03

        题意

        a+ba+b

        思路

        这题不需要思路

        方法

        也不需要方法

        代码

        #include <iostream> 
        using namespace std; 
        int main() { 
            int a, b; 
            cin >> a >> b; 
            cout << a + b << endl; 
            return 0; 
        }
        
        • 0
          @ 2024-1-19 13:11:50

          A + B Probelm 氵到要死

          C++的入门题吧,输入 aabb,输出a+ba+b

          #include<bits/stdc++.h>
          using namespace std;
          int main(){
              int a, b;
              cin >> a >> b;
              cout << a + b;
              return 0;
          }
          
          • 0
            @ 2024-1-18 20:58:43
            #include<bits/stdc++.h>
            using namespace std;
            struct Plus{
            long long a,b;
            void in(){
            cin>>a>>b;
            }
            void out(){
            cout<<a+b;
            }
            };
            int main(){
            Plus a_plus_b;
            a_plus_b.in();
            a_plus_b.out();
            return 0;
            }
            
            
            • 0
              @ 2024-1-13 10:27:45

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

              return 0;
              

              } 这都不会就过分了啊 👍

              • 0
                @ 2023-11-3 21:22:55

                LCT解法

                #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);
                        connect(A,B);
                        cut(A,B);
                        connect(A,B);
                    printf("%d\n",query(A,B)); 
                    return 0;
                }
                
                • 0
                  @ 2023-10-27 22:50:04
                  #include<bits/stdc++.h>
                  using namespace std;
                  const int N=100001;
                  int a[N],b[N],ml;
                  void add(int a[],int b[])
                  {
                  	int cnt=0;
                  	for(int i=1;i<=ml+1;i++)
                  	{
                  		cnt+=a[i]+b[i];
                  		a[i]=cnt%10;
                  		cnt/=10;
                  	}
                  	return;
                  }
                  void print(int a[])
                  {
                  	int i;
                  	for(i=ml+1;i>0&&!a[i];i--);
                  	if(!i)
                  	{
                  		cout<<0;
                  		return;
                  	}
                  	while(i)
                  	{
                  		cout<<a[i--];
                  	}
                  }
                  int main()
                  {
                  	string sa,sb;
                  	cin>>sa>>sb;
                  	int la=sa.size(),lb=sb.size();
                  	ml=la>lb?la:lb;
                  	for(int i=1;i<=la;i++)
                  	{
                  		a[i]=sa[la-i]-'0';
                  	}
                  	for(int i=1;i<=lb;i++)
                  	{
                  		b[i]=sb[lb-i]-'0';
                  	}
                  	add(a,b);
                  	print(a);
                  	return 0;
                  }
                  
                  • 0
                    @ 2023-10-15 17:46:10
                    #include<iostream>//头文件
                    using namespace std;//命名空间
                    int main()
                    {
                         int a, b;//定义
                         cin>> a>> b;//输入
                         cout<< a + b;//输出
                         return 0;
                    }
                    
                    • 0
                      @ 2023-10-10 22:50:59
                      /*****************
                      备注:
                      *****************/
                      #include <iostream>
                      using namespace std;
                      #define LL long long
                      #define MAXM 3010
                      #define MAXN 3010
                      const int N =1e5+10;
                      const int INF =0x3f3f3f3f;
                      int main ()
                      {
                          LL a,b;
                          cin>>a>>b;
                          cout<<a+b;
                         return 0;
                      }
                      
                      
                      • 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. 最后,得到的结果链表即为相加后的结果。
                          • -1
                            @ 2023-12-26 9:30:44

                            这是全站最简单的题,也是所有萌新都会做到的题。

                            #include<bits/stdc++.h>
                            using namespace std;
                            int main()
                            {
                            int a,b;
                            cin>>a>>b;
                            cout<<a+b;
                            return 0;
                            }
                            
                            • -1
                              @ 2023-12-23 11:24:00
                              #include<iostream>
                              using namespace std; 
                              int main()
                              {
                                  int a,b;
                                  cin>a>b;
                                  cout<a+b;
                                  return 0;
                              }
                              
                              • -1
                                @ 2023-12-7 0:26:43
                                line = list(map(int,input().split()))
                                print(line[0]+line[1])
                                
                                • -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               )
                                        

                                        信息

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