173 条题解

  • 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
        @ 2024-1-7 13:23:33

        童鞋们你们好!

        打开这道题,就相当于你们迈出了万里 OI 路的第一步。让我们重视这一步!

        这里提醒同学们:好的代码风格是非常重要的。大家一定要养成良好的代码风格

        来看看我打的代码:

        #include<bits/stdc++.h> //万能头
        using namespace std; //使用std这个命名空间
        
        int main() {
            int a, b; //1e6 int够用
            cin >> a >> b; //cin = console+input 标准读入
            cout << a + b; //cout = console+output 标准输出
            return 0; //不要忘了一个华丽的结尾
        }
        

        最后想请童鞋们注意:强烈建议cin/cout<</>>符号前后打一个空格!这样能让你的代码更加美观!

        这就是我们万里编程路的第一步。在以后的刷题中,大家会遇到更多的难题。希望大家能不忘初心,砥砺前行! 说歪了

        感谢观看!

        • 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. 最后,得到的结果链表即为相加后的结果。
                • 0
                  @ 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               )
                  
                  • 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
                    @ 2022-11-9 21:16:25

                    使用 C++ 风格的输入输出

                    #include <bits/stdc++.h>//头文件,可以暂时理解为告诉编译器你要拿标准库中的函数来用
                    using namespace std;    //如果不想引入整个 std 命名空间,你需要使用 
                    int main() {            //std::cin、std::cout、std::endl
                        int a, b;           //定义整形变量 a 和 b,它们可存储的整数范围约为 ±21 亿,
                        cin >> a >> b;      //对于本题的数据范围绰绰有余;从标准输入中读入两个值并赋给 a, b
                        cout << a + b;      //输出结果。你也可以先使用另一个变量存储结果,但在这里没什么意义
                        return 0;           //返回 0 以外的值会让操作系统或在线判题系统认为你的程序异常退出
                    }                       //最后的 return 0; 也可以不写,编译器会自动帮你加上正常退出
                    

                    使用 C 语言风格的输入输出

                    #include <bits/stdc++.h>
                    using namespace std;
                    int main() {
                        int a, b;               //%d 是整形的占位符
                        scanf("%d %d", &a, &b); //输入非字符串时你需要在变量名前面加上取地址符 &
                        printf("%d", 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
                        @ 2025-2-13 10:35:01

                        这题只要输出两数之和就行了,代码:

                        #include<bits/stdc++.h>
                        using namespace std;
                        signed main(){
                        	int a, b;
                        	cin >> a >> b;
                        	cout << a + b;
                        	return 0;
                        }
                        
                        
                        • -1
                          @ 2025-1-24 11:59:01

                          文言文

                          由【键盘】入之甲、乙二整形元素。
                          以操作符【+】计算甲、乙之和。
                          存入另一整形元素丙。书之。
                          

                          伪代码(PQ)

                          set keyboard as stdin
                          set screen as stdout
                          input int1024 a b
                          c=a(operator +)b
                          output c as int1024
                          

                          伪代码(XD20)
                          这个在XD22中也可运行

                          function main
                          begin.
                          stdin a
                          stdin b
                          stdout a+b
                          end.
                          

                          伪代码(XD22)

                          select keyboard as stdin
                          select screen as stdout
                          gnu -O2 -Wall
                          function main
                          begin.
                          stdin a
                          stdin b
                          stdout a+b
                          end.
                          
                          

                          伪代码(Z)

                          select keyboard as input
                          select screen as output
                          select windows11 as system
                          select Z22 as language
                          select ZS22 as compiler
                          begin.
                          read a
                          read b
                          write a+b
                          end.
                          flush.
                          

                          Pascal

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

                          C++

                          #include<bits/stdc++.h>
                          using namespace std;
                          int fu=1,f=1,a,b,c=0;
                          int main(){
                              cin>>a>>b;
                              if(a<0&&b>0)fu=2;
                              if(a>0&&b<0)fu=3;
                              if(a<0&&b<0)f=-1;
                              if(a==0){cout<<b;return 0;}
                              if(b==0){cout<<a;return 0;} 
                              a=abs(a);
                              b=abs(b);
                              if(a>b&&fu==3)f=1;
                              if(b>a&&fu==3)f=-1;
                              if(b>a&&fu==2)f=1;
                              if(b<a&&fu==2)f=-1;
                              if(fu==1)c=a+b;
                              if(fu>1)c=max(a,b)-min(a,b);
                              c*=f;
                              cout<<c;
                              return 0;
                          }
                          
                          • -1
                            @ 2024-12-29 14:17:40

                            c++

                            #include<bits/stdc++.h>
                            typedef long long ll;
                            using namespace std;
                            ll a,b;
                            int main(){
                            	ios::sync_with_stdio(false);
                            	cin.tie(0),cout.tie(0);
                            	cin>>a>>b;
                            	cout<<a+b<<endl;
                            	return 0;
                            }
                            • -1
                              @ 2024-11-26 17:23:15

                              曾经的我:

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

                              现在的我:

                              #include<iostream>
                              #include<string>
                              using namespace std;
                              int n1[501];
                              int m1[501];
                              int result[501];
                              string n,m;
                              int main(){
                              	cin>>n>>m;
                              	int ns,ms;
                              	ns=n.size();
                              	ms=m.size();
                              	for(int i=ns-1,j=1;i>=0;i--,j++){
                              		n1[j]=n[i]-'0';
                              	}
                              	for(int i=ms-1,j=1;i>=0;i--,j++){
                              		m1[j]=m[i]-'0'; 
                              	}
                              	int j=ns>ms?ns:ms;
                              	for(int i=1;i<=j;i++){
                              		result[i]+=m1[i]+n1[i];
                              		result[i+1]=result[i]/10;
                              		result[i]=result[i]%10;
                              	}
                              	if(result[j+1]){
                              		j++;
                              	}
                              	for(int i=j;i>=1;i--){
                              		cout<<result[i];
                              	}
                              	return 0;
                              }
                              

                              感觉没啥变化

                              • -1
                                @ 2024-11-24 19:42:45

                                c++

                                #include <iostream>
                                using naemspace std;
                                
                                signed main(){
                                  int a,b;
                                  cin>>a>>b;
                                  cout<<a + b;
                                  return 0;
                                }
                                • -1
                                  @ 2024-11-12 20:56:46

                                  H1000题解

                                  这是一道经典入门题目

                                  主要题意

                                  输入 aabb 然后输出它们的和。

                                  解题思路

                                  太简单了,跳过吧,看代码详解。

                                  上代码!

                                  #include<bits/stdc++.h>//万能头文件 
                                  using namespace std;//调用std库 
                                  long long a,b;//定义两个整数 
                                  int main()
                                  {
                                  	cin>>a>>b;//输入 
                                  	cout<<a+b;//输出a与b的和
                                  	return 0;//好习惯 
                                  }
                                  
                                  
                                  • -1
                                    @ 2024-11-8 17:44:00

                                    注:此代码不支持C++23(O2)。

                                    #include<bits/stdc++.h>
                                    #define short long long
                                    #define int long long
                                    #define float long double
                                    #define double long double
                                    #define char wchar_t
                                    #define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
                                    using namespace std;
                                    signed main(){
                                        ios;
                                        int a,b;//定义a,b
                                        cin>>a>>b;//输入a,b
                                        cout<<a+b;//输出a+b
                                        return 0;//结束程序
                                    }
                                    
                                    • -1
                                      @ 2024-11-5 20:46:06

                                      一道简单的入门题目,适合给新手做.

                                      #include<iostream>
                                      using namespace std;
                                      int main()
                                      {
                                          int a,b;
                                          scanf("%d%d",&a,&b);
                                          printf("%d",a+b);
                                          return 0;
                                      }
                                      
                                      • -1
                                        @ 2024-11-4 15:00:23

                                        #include <stdio.h>

                                        int main() { int a,b; scanf("%d%d",&a,&b); printf("%d\n", a+b); return 0; }

                                        信息

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