198 solutions

  • 157
    @ 2021-10-5 13:19:34

    尽管 A + B Problem 是十分经典的入门题目,也希望大家能够在题解区友善交流。 HydroOJ 致力于提供一个友善的交流学习平台,请不要发布误导性题解,谢谢! 您可以给您喜欢的题解投票,让更多的人看到它们。同时,题解的评分也会影响你在排名中的贡献一栏分数。

    我们认为优质的题解需要:正确的代码高亮,简洁而有效的注解,思路清晰,便于理解,无冗长板子,不定义非常用宏。

    • 40
      @ 2021-10-13 17:00:49

      简单的入门测试题

      本题各种语言的程序写法:(不知道Hydro有没有这些语言

      C

      #include <stdio.h>
      
      int main()
      {
          int a,b;
          scanf("%d%d",&a,&b);
          printf("%d\n", a+b);
          return 0;
      }
      

      C++

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

      Pascal

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

      Python2

      s = raw_input().split()
      print int(s[0]) + int(s[1])
      

      Python3

      s = input().split()
      print(int(s[0]) + int(s[1]))
      

      Java

      import java.io.*;
      import java.util.*;
      public class Main {
          public static void main(String args[]) throws Exception {
              Scanner cin=new Scanner(System.in);
              int a = cin.nextInt(), b = cin.nextInt();
              System.out.println(a+b);
          }
      }
      

      JavaScript (Node.js)

      const fs = require('fs')
      const data = fs.readFileSync('/dev/stdin')
      const result = data.toString('ascii').trim().split(' ').map(x => parseInt(x)).reduce((a, b) => a + b, 0)
      console.log(result)
      process.exit() // 请注意必须在出口点处加入此行
      

      Ruby

      a, b = gets.split.map(&:to_i)
      print a+b
      

      PHP

      <?php
      $input = trim(file_get_contents("php://stdin"));
      list($a, $b) = explode(' ', $input);
      echo $a + $b;
      

      Rust

      use std::io;
      
      fn main(){
          let mut input=String::new();
          io::stdin().read_line(&mut input).unwrap();
          let mut s=input.trim().split(' ');
      
          let a:i32=s.next().unwrap()
                     .parse().unwrap();
          let b:i32=s.next().unwrap()
                     .parse().unwrap();
          println!("{}",a+b);
      }
      

      Go

      package main
      
      import "fmt"
      
      func main() {
          var a, b int
          fmt.Scanf("%d%d", &a, &b)
          fmt.Println(a+b)
      }
      

      C# Mono

      using System;
      
      public class APlusB{
          private static void Main(){
              string[] input = Console.ReadLine().Split(' ');
              Console.WriteLine(int.Parse(input[0]) + int.Parse(input[1]));
          }
      }
      

      Visual Basic Mono

      Imports System
      
      Module APlusB
          Sub Main()
              Dim ins As String() = Console.ReadLine().Split(New Char(){" "c})
              Console.WriteLine(Int(ins(0))+Int(ins(1)))
          End Sub
      End Module
      

      Kotlin

      fun main(args: Array<String>) {
          val (a, b) = readLine()!!.split(' ').map(String::toInt)
          println(a + b)
      }
      

      Haskell

      main = do
          [a, b] <- (map read . words) `fmap` getLine
          print (a+b)
      

      Scala

      object Main extends App {
          println(scala.io.StdIn.readLine().split(" ").map(_.toInt).sum)
      }
      

      Perl

      my $in = <STDIN>;
      chomp $in;
      $in = [split /[\s,]+/, $in];
      my $c = $in->[0] + $in->[1];
      print "$c\n";
      

      文言

      施「require('fs').readFileSync」於「「/dev/stdin」」。名之曰「數據」。
      施「(buf => buf.toString().trim())」於「數據」。昔之「數據」者。今其是矣。
      施「(s => s.split(' '))」於「數據」。昔之「數據」者。今其是矣。
      注曰。「「文言尚菜,無對象之操作,故需 JavaScript 之语法」」。
      
      夫「數據」之一。取一以施「parseInt」。名之曰「甲」。
      夫「數據」之二。取一以施「parseInt」。名之曰「乙」。
      
      加「甲」以「乙」。書之。
      
      • @ 2024-1-25 17:08:05

        我的Python3

        print(int(input()) + int(input())
        

        得了(一行代码)

      • @ 2024-2-3 16:55:12

        只要你想就有

      • @ 2024-7-23 20:03:54

        @ 你这样不行,要加split

      • @ 2024-7-29 15:26:31

        文言……

      • @ 2024-10-28 16:22:19

        python代码是不是得在split的括号里加个空格啊 【感谢点拨】

      • @ 2024-11-27 22:07:19

        @ 这个写法不满足题目输入要求,要求输入一行,两个数之间用空格隔开。

        你程序写法需要在每输入第一个数后,按下回车键。

      • @ 2025-3-15 19:23:14

        文言!hahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahaha

    • 28
      @ 2021-8-24 13:40:55

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

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

      管理大大求过

      • @ 2023-12-31 14:00:33

        这道题应该用long long类型的变量进行存储因为数值范围是10610^6,int存不下,建议改一下

      • @ 2024-1-30 13:44:38

        @。 在大多数编程环境中,int 类型的大小通常为 4 字节(32 位),其范围为 -2,147,483,648 到 2,147,483,647(常见的采用补码表示法)。这是根据 C99 标准中的 INT_MIN(最小值)和 INT_MAX(最大值)来定义的。

      • @ 2025-6-26 13:13:49

        HydroOJ 曾因为紫荆花之恋而封禁了一个账号,它的用户名是:

      • @ 2025-11-5 21:13:16

        @ long其实也够了

    • 10
      @ 2021-3-7 18:45:04
      #include<bits/stdc++.h>//万能头文件
      using namespace std;//使用标准命名空间
      int main()//主函数
      {
      	int a,b;
      	cin>>a>>b;
      	cout<<a+b;
      	return 0;//好习惯
      }
      
      • @ 2025-6-2 20:04:54

        两个10^6相加会超int

    • 4
      @ 2021-11-1 16:48:34

      请大家不要发恶搞题解来误导新手,谢谢!

      Python 题解,输入 aabb,输出 a+ba+b
      提醒一句,Python 需要用 split() 切片,而且要转成 int 型。

      a=input().split()
      print(int(a[0])+int(a[1]))
      
      • @ 2024-1-18 21:02:38

        你可以在定义时就转成int

        a=int(input())
        
      • @ 2024-12-13 21:42:21

        @ 错啦,是map(int, input().split())

    • 3
      @ 2025-7-9 17:02:45

      前言

      大家好,我是 ArmeriaLeap,这是我在 Hydro Online Judge 上的第一篇题解!希望这篇题解能对你有帮助,如果觉得质量不错的话请点个小小的赞喵~

      本篇题解适合 C++ 选手食用喵~

      题意

      给定了两个整数 aabb,求 a+ba+b 的值,其中 a,b106a,b\le10^6 喵~

      分析

      为了解决这个问题,我们都需要处理什么呢?

      • 程序的框架
      • 输入 a,ba,b
      • 计算 a+ba+b
      • 输出
      • 结束程序

      现在,让我们一点点来处理吧喵!

      框架

      一个正常的程序,是由很多很多的部分组成的。今天,我们一起来认识它最关键的三个部分——头文件、命名空间和主函数!

      头文件

      所谓“头”文件,我们肯定要把它写在程序的开头喵~那“文件”又是什么呢?是编译器为我们提供的函数库喵!

      举个例子:如果你想调用 cstdio 中的函数,你需要引用 cstdio 这个文件。怎么引用呢?你可以在程序中添加 #include <文件名> 这条语句。

      如果你是个懒猫,不想写那么多的 #include,你可以直接敲下这么一行头文件:#include <bits/stdc++.h>。这是万能头,包含了所有的头文件喵!

      命名空间

      我们来举一个贴近生活的例子。李明养了一只猫叫“胖橘”,王红也有一只叫“胖橘”的猫,那怎么分清这两只猫呢?命名空间可就派上用场了!

      平时,我们用的命名空间都是 std,所以我们就应该在头文件下面加上 using namespace std;

      主函数

      就是最重要的函数啦~类型必须是 int,名字必须叫 main(),最后必须 return 0;,其他的就没有任何限制了喵!根据题目去编写吧!

      输入

      推荐使用 iostream 库中的 cincin >> a; 就代表输入 aacin >> a >> b; 代表输入 a,ba, b

      计算

      细心的你一定发现了吧,键盘上的 + 是可以直接放在两个变量之间的喵~

      输出

      cin 的好伙伴——cout!输出 aa 就是 cout << a;,如果你想加上换行,endl 在像你招手喵~

      代码

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

      完结撒花!

      • 1
        @ 2025-11-1 10:03:34

        我们可以发现,a 和 b 的数据范围特别大,居然超过了 long long!我们只好拿出秘密武器:高精度。我们可以发现 (a+b)2=a2+b2+2ab(完全平方公式)。所以可以使用**高精度乘法算出来 a2,b2,2ab,再使用高精度开根算出绝对值 a+b**。这时候我们就需要分类讨论。若 a 为正数且 b 为正数,则 a+b 为正数。若 a 为负数且 b 为负数,则 a+b 为负数。若 a 与 b 一正一负,则要比较 a 与 b 的绝对值,用到高精度比较。

        来人,把朕的代码端上来!!!

        #include <bits/stdc++.h>
        using namespace std;
        string qf (string a)
        {
        	if (a[0] == '-') return a.substr (1 , a.size () - 1);
        	return "-" + a;
        }
        string operator - (string a) {return qf (a);}
        string gjc (string a , string b)
        {
        	if (a[0] == '-' && b[0] == '-') return gjc (- a , - b);
        	else if (a[0] == '-') return - gjc (- a , b);
        	else if (b[0] == '-') return - gjc (a , - b);
        	int ans[a.size () + b.size ()] = {};
        	reverse (a.begin () , a.end ());
        	reverse (b.begin () , b.end ());
        	for (int i = 0;i < a.size ();i ++)
        		for (int j = 0;j < b.size ();j ++) ans[i + j] += (a[i] - '0') * (b[j] - '0');
        	for (int i = 0;i < a.size () + b.size ();i ++)
        		if (ans[i] > 9)
        		{
        			int x = ans[i] % 10 , y = ans[i] / 10;
        			ans[i] = x;
        			ans[i + 1] += y;
        		}
        	string ans2 = "";
        	for (int i = 1;i <= a.size () + b.size ();i ++) ans2 += (char) (ans[i - 1] + '0');
        	if (ans2[ans2.size () - 1] == '0') ans2 = ans2.substr (0 , ans2.size () - 1);
        	reverse (ans2.begin () , ans2.end ());
        	return ans2;
        }
        string max (string a , string b)
        {
        	if (a[0] == '-' && b[0] == '-')
        	{
        		if (- max (- a , - b) == a) return b;
        		return a;
        	}
        	else if (a[0] == '-') return b;
        	else if (b[0] == '-') return a;
        	else if (a.size () > b.size ()) return a;
        	else if (a.size () < b.size ()) return b;
        	else
        	{
        		for (int i = 0;i < a.size ();i ++)
        			if (a[i] > b[i]) return a;
        			else if (a[i] < b[i]) return b;
        		return a;
        	}
        }
        string min (string a , string b)
        {
        	if (max (a , b) == a) return b;
        	return a;
        }
        string gjj (string a , string b);
        string cut (string a , string b)
        {
        	if (a[0] == '-' && b[0] == '-') return cut (- b , - a);
        	else if (a[0] == '-') return - gjj (- a , b);
        	else if (b[0] == '-') return gjj (b , - a);
        	else if (max (a , b) != a) return - cut (b , a);
        	reverse (a.begin () , a.end ());
        	reverse (b.begin () , b.end ());
        	string ans = "";
        	for (int i = 1;i <= a.size () + 1;i ++) ans += "0";
        	for (int i = 0;i < b.size ();i ++) ans[i] += a[i] - b[i];
        	for (int i = b.size ();i < a.size ();i ++) ans[i] = a[i];
        	for (int i = 0;i < ans.size ();i ++)
        		if (ans[i] < '0')
        		{
        			ans[i] += 10;
        			ans[i + 1] -= 1;
        		}
        	while (ans.size () > 1 && ans[ans.size () - 1] == '0') ans = ans.substr (0 , ans.size () - 1);
        	reverse (ans.begin () , ans.end ());
        	return ans;
        }
        string gjj (string a , string b)
        {
        	if (a[0] == '-' && b[0] == '-') return - gjc (- a , - b);
        	else if (a[0] == '-') return cut (b , - a);
        	else if (b[0] == '-') return cut (a , - b);
        	if (a.size () < b.size ()) swap (a , b);
        	reverse (a.begin () , a.end ());
        	reverse (b.begin () , b.end ());
        	string ans = "";
        	for (int i = 1;i <= a.size () + 1;i ++) ans += "0";
        	for (int i = 0;i < b.size ();i ++) ans[i] += a[i] - '0' + b[i] - '0';
        	for (int i = b.size ();i < a.size ();i ++) ans[i] = a[i];
        	for (int i = 0;i < ans.size ();i ++)
        		if (ans[i] > '9')
        		{
        			ans[i] -= 10;
        			ans[i + 1] += 1;
        		}
        	if (ans[ans.size () - 1] == '0') ans = ans.substr (0 , ans.size () - 1);
        	reverse (ans.begin () , ans.end ());
        	return ans;
        }
        string dev (string b , int a)
        {
        	if (a < 0 && b[0] == '-') return dev (- b , - a);
        	else if (a < 0) return - dev (b , - a);
        	else if (b[0] == '-') return - dev (- b , a);
        	while (a % 10 == 0 && b[b.size () - 1] == '0')
            {
                a /= 10;
                b = b.substr (0 , b.size () - 1);
            }
        	string ans = "";
        	int yu = 0;
        	for (int i = 0;i < b.size ();i ++)
        	{
        		yu = yu * 10 + b[i] - '0';
        		ans += yu / a + '0';
        		yu %= a;
        	}
        	while (ans.size () > 1 && ans[0] == '0') ans = ans.substr (1);
        	return ans;
        }
        string operator / (string a , int b) {return dev (a , b);}
        string operator * (string a , string b) {return gjc (a , b);}
        string operator + (string a , string b) {return gjj (a , b);}
        string operator - (string a , string b) {return cut (a , b);}
        string sqrt (string s)
        {
        	if (s == "0") return "0";
        	if (s == "1") return "1";
        	string l = "1" , r = "1" , ans , dan = "1";
        	for (int i = 1;i < s.size () / 2;i ++) l += "0";
        	for (int i = 1;i <= s.size () / 2 + 1;i ++) r += "0";
        	while (max (l , r) == r)
        	{
        		string mid = (l + r) / 2;
        		if (max (mid * mid , s) == s)
        		{
        			ans = mid;
        			l = gjj (mid , dan);
        		}
        		else r = mid - dan;
        	}
        	return ans;
        }
        signed main ()
        {
        	string a , b , c = "2";
        	cin >> a >> b;
        	if (a[0] == '-' && b[0] == '-')	cout << - sqrt (a * a + b * b + c * a * b);
        	else if (a[0] == '-')
        	{
        		if (max (- a , b) == b) cout << sqrt (a * a + b * b + c * a * b);
        		else cout << - sqrt (a * a + b * b + c * a * b);
        	}
        	else if (b[0] == '-')
        	{
        		if (max (- b , a) == a) cout << sqrt (a * a + b * b + c * a * b);
        		else cout << - sqrt (a * a + b * b + c * a * b);
        	}
        	else cout << sqrt (a * a + b * b + c * a * b);
        }
        

        哔~~

        • @ 2025-11-5 21:15:52

          那代码也不用这么长吧

      • 1
        @ 2025-6-7 9:19:53

        加法是C++自带的操作。 代码如下:

        #include<bits/stdc++.h>//头文件
        using namespace std;
        int main(){
          ios::sync_with_stdio(0);
        	cin.tie(0);
          cout.tie(0);//关流
          int a, b;//不会爆
          cin >> a >> b;
          cout << a + b;
          return 0;//好习惯
        }
        
        
        • 1
          @ 2025-5-3 15:32:02

          代码十分简单

          Code:

          #include<bits/stdc++.h>
          using namespace std;
          int main(){
          	ios::sync_with_stdio(false);
          	cin.tie(0);
          	cout.tie(0);
          	int a,b;
          	cin>>a>>b;
          	cout<<a+b<<endl;
          	return 0;
          }
          
          • 1
            @ 2025-5-2 11:55:45

            思路:

            输入两个数,输出这两个数的和。

            AC 代码:

            正常一点的:

            #include<bits/stdc++.h>
            #define int long long //以防爆int,所以开一个long long。
            using namespace std;
            
            int a,b;//定义两个变量,名字叫a和b。
            
            signed main(){
            	cin >> a >> b //输入。
            ;	cout << a + b //输出。
            ;	return 0
            ;}
            

            闲着没事干手写头文件(?)的:

            #ifndef _INC_MINGW_SECAPI
            #define _INC_MINGW_SECAPI
            
            #if defined(__cplusplus) && (MINGW_HAS_SECURE_API == 1)
            #ifndef _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES
            #define _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES 1         /* default to 1 */
            #endif 
            
            #ifndef _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES_MEMORY
            #define _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES_MEMORY 0  /* default to 0 */
            #endif 
            
            #ifndef _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES
            #define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 0       /* default to 0 */
            #endif
            
            #ifndef _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT
            #define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT 0 /* default to 0 */
            #endif 
            
            #ifndef _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_MEMORY
            #define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_MEMORY 0 /* default to 0 */
            #endif 
            
            #else
            
            #undef _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES
            #undef _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES_MEMORY
            #undef _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES
            #undef _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT
            #undef _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_MEMORY
            #define _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES 0
            #define _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES_MEMORY 0
            #define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 0
            #define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT 0
            #define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_MEMORY 0
            #endif 
            
            #define __MINGW_CRT_NAME_CONCAT1(sym) ::sym
            #define __MINGW_CRT_NAME_CONCAT2(sym) ::sym##_s
            #define __MINGW_CRT_NAME_INSECURE(sym) ::__insecure__##sym
            #define __MINGW_CRT_NAME_INSECURE_DEF(sym) __insecure__##sym
            
            #ifdef __cplusplus
            extern "C++" {
            template <bool __test, typename __dsttype>
              struct __if_array;
            template <typename __dsttype>
              struct __if_array <true, __dsttype> {
                typedef __dsttype __type;
            };
            }
            #endif /*__cplusplus*/
            
            #if (_CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES == 1)
            #define __CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES_0_2_(__ret,__func,__type1,__attrib1,__arg1,__type2,__attrib2,__arg2,__type3,__attrib3,__arg3)\
              extern "C" { _CRTIMP __ret __cdecl __func(__type1 * __attrib1 __arg1, __type2 __attrib2 __arg2, __type3 __attrib3 __arg3); }\
              extern "C++" {\
                template <size_t __size> inline\
                __ret __cdecl __func(\
                __type1 (&__arg1)[__size],\
                __type3 __attrib3 (__arg3)) {\
                  return __MINGW_CRT_NAME_CONCAT1(__func)(__arg1,__size,__arg3);\
                }\
              }
            #else
            #define __CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES_0_2_(__ret,__func,__type1,__attrib1,__arg1,__type2,__attrib2,__arg2,__type3,__attrib3,__arg3)\
              _CRTIMP __ret __cdecl __func(__type1 * __attrib1 __arg1, __type2 __attrib2 __arg2, __type3 __attrib3 __arg3);
            #endif
            
            
            #if (_CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES_MEMORY == 1)
            #define __CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES_MEMORY_0_3_(__ret,__func,__type1,__attrib1,__arg1,__type2,__attrib2,__arg2,__type3,__attrib3,__arg3,__type4,__attrib4,__arg4)\
              extern "C" { _CRTIMP __ret __cdecl __func(__type1 * __attrib1 __arg1, __type2 __attrib2 __arg2, __type3 __attrib3 __arg3, __type4 __attrib4 __arg4); }\
              extern "C++" {\
                template <size_t __size> inline\
                __ret __cdecl __func(\
                __type1 (&__arg1)[__size],\
                __type3 __attrib3 (__arg3),\
                __type4 __attrib4 (__arg4)) {\
                  return __MINGW_CRT_NAME_CONCAT1(__func)(__arg1,__size,__arg3,__arg4);\
                }\
              }
            #else
            #define __CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES_MEMORY_0_3_(__ret,__func,__type1,__attrib1,__arg1,__type2,__attrib2,__arg2,__type3,__attrib3,__arg3,__type4,__attrib4,__arg4)\
              _CRTIMP __ret __cdecl __func(__type1 * __attrib1 __arg1, __type2 __attrib2 __arg2, __type3 __attrib3 __arg3, __type4 __attrib4 __arg4);
            #endif 
            
            #if (_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES == 1)
            #define __CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_0_2_(__ret,__func,__type1,__attrib1,__arg1,__type2,__attrib2,__arg2)\
              extern "C" {\
                inline __ret __cdecl __MINGW_CRT_NAME_INSECURE_DEF(__func)(__type1 * __attrib1 __arg1, __type2 __attrib2 __arg2){\
                  _CRTIMP __ret __cdecl __func(__type1 * __attrib1 __arg1, __type2 __attrib2 __arg2);\
                  return __func(__arg1,__arg2);\
                }\
              }\
              extern "C++" {\
                template <size_t __size> inline\
                __ret __cdecl __func(\
                __type1 (&__arg1)[__size],\
                __type2 (__arg2)) {\
                  return __MINGW_CRT_NAME_CONCAT2(__func) (__arg1,__size,__arg2) == 0 ? __arg1 : NULL;\
                }\
                template <typename __t1> inline \
                __t1 __cdecl __func(\
                __t1 __attrib1 (__arg1),\
                __type2 __attrib2 (__arg2)) {\
                  return __MINGW_CRT_NAME_INSECURE(__func)(__arg1,__arg2);\
                }\
              }
            #else
            #define __CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_0_2_(__ret,__func,__type1,__attrib1,__arg1,__type2,__attrib2,__arg2)\
              _CRTIMP __ret __cdecl __func(__type1 * __attrib1 __arg1, __type2 __attrib2 __arg2) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
            #endif 
            
            #if (_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT == 1) && (_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES == 1)
            #define __CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT_0_3_(__ret,__func,__type1,__attrib1,__arg1,__type2,__attrib2,__arg2,__type3,__attrib3,__arg3)\
              extern "C" {\
                inline __ret __cdecl __MINGW_CRT_NAME_INSECURE_DEF(__func)(__type1 * __attrib1 __arg1, __type2 __attrib2 __arg2, __type3 __attrib3 __arg3){\
                  _CRTIMP __ret __cdecl __func(__type1 * __attrib1 __arg1, __type2 __attrib2 __arg2, __type3 __attrib3 __arg3);\
                  return __func(__arg1,__arg2,__arg3);\
                }\
              }\
              extern "C++" {\
                template <size_t __size> inline\
                __ret __cdecl __func(\
                __type1 (&__arg1)[__size],\
                __type2 __attrib2 (__arg2),\
                __type3 __attrib3 (__arg3)) {\
                  return __MINGW_CRT_NAME_CONCAT2(__func) (__arg1,__size,__arg2,__arg3) == 0 ? __arg1 : NULL;\
                }\
                template <typename __t1> inline \
                __ret __cdecl __func(\
                __t1 (__arg1),\
                __type2 __attrib2 (__arg2),\
                __type3 __attrib3 (__arg3)) {\
                  return __MINGW_CRT_NAME_INSECURE(__func) (__arg1,__arg2,__arg3);\
                }\
              }
            
            
            #define __CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT_1_4_(__ret,__imp_attrib,__func,__real_func,__type1,__attrib1,__arg1,__type2,__attrib2,__arg2,__type3,__attrib3,__arg3,__type4,__attrib4,__arg4)\
              extern "C" {\
                inline __ret __cdecl __MINGW_CRT_NAME_INSECURE_DEF(__func)(__type1 * __attrib1 __arg1, __type2 __attrib2 __arg2, __type3 __attrib3 __arg3, __type4 __attrib4 __arg4){\
                  __imp_attrib __ret __cdecl __func(__type1 * __attrib1 __arg1, __type2 __attrib2 __arg2, __type3 __attrib3 __arg3, __type4 __attrib4 __arg4);\
                  return __func(__arg1,__arg2,__arg3,__arg4);\
                }\
              }\
              extern "C++" {\
                template <size_t __size> inline\
                __ret __cdecl __func(\
                __type1 (&__arg1)[__size],\
                __type2 __attrib2 (__arg2),\
                __type3 __attrib3 (__arg3),\
                __type4 __attrib4 (__arg4)) {\
                  return __MINGW_CRT_NAME_CONCAT1(__real_func) (__arg1,__size,__arg2,__arg3,__arg4) == 0 ? __arg1 : NULL;\
                }\
                template <typename __t1> inline \
                __ret __cdecl __func(\
                __t1 (__arg1),\
                __type2 __attrib2 (__arg2),\
                __type3 __attrib3 (__arg3),\
                __type4 __attrib4 (__arg4)) {\
                  return __MINGW_CRT_NAME_INSECURE(__func) (__arg1,__arg2,__arg3,__arg4);\
                }\
              }
            
            #else
            #define __CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT_0_3_(__ret,__func,__type1,__attrib1,__arg1,__type2,__attrib2,__arg2,__type3,__attrib3,__arg3)\
              _CRTIMP __ret __cdecl __func(__type1 * __attrib1 __arg1, __type2 __attrib2 __arg2, __type3 __attrib3 __arg3) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
            #define __CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT_1_4_(__ret,__imp_attrib,__func,__real_func,__type1,__attrib1,__arg1,__type2,__attrib2,__arg2,__type3,__attrib3,__arg3,__type4,__attrib4,__arg4)\
              __imp_attrib __ret __cdecl __func(__type1 * __attrib1 __arg1, __type2 __attrib2 __arg2, __type3 __attrib3 __arg3, __type4 __attrib4 __arg4) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
            #endif
            
            
            #if (_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_MEMORY == 1)
            #define __CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_MEMORY_0_3_(__ret,__func,__type1,__attrib1,__arg1,__type2,__attrib2,__arg2,__type3,__attrib3,__arg3)\
              extern "C" {_CRTIMP __ret __cdecl __func(__type1 * __attrib1 __arg1, __type2 __attrib2 __arg2, __type3 __attrib3 __arg3) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;}\
              extern "C++" {\
                template <size_t __size, typename __dsttype> inline\
                typename __if_array < (__size > 1), void * >::__type __cdecl __func(\
                __dsttype (&__arg1)[__size],\
                __type2 __attrib2 (__arg2),\
                __type3 __attrib3 (__arg3)) {\
                  return __MINGW_CRT_NAME_CONCAT2(__func) (__arg1,__size * sizeof(__dsttype),__arg2,__arg3) == 0 ? __arg1 : NULL;\
                }\
              }
            #else
            #define __CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_MEMORY_0_3_(__ret,__func,__type1,__attrib1,__arg1,__type2,__attrib2,__arg2,__type3,__attrib3,__arg3)\
              _CRTIMP __ret __cdecl __func(__type1 * __attrib1 __arg1, __type2 __attrib2 __arg2, __type3 __attrib3 __arg3) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
            #endif
            
            #endif 
            
            #include<bits/stdc++.h>
            //其实只需要这一行头文件就够了。
            #define int long long //以防爆int,所以开一个long long。
            using namespace std;
            
            int a,b;//定义两个变量,名字叫a和b。
            
            signed main(){
            	cin >> a >> b //输入。
            ;	cout << a + b //输出。
            ;	return 0
            ;}
            
            • 1
              @ 2025-4-1 19:28:29
              #include <algorithm>
              #include <bitset>
              #include <cctype>
              #include <cerrno>
              #include <clocale>
              #include <cmath>
              #include <complex>
              #include <cstdio>
              #include <cstdlib>
              #include <cstring>
              #include <ctime>
              #include <deque>
              #include <exception>
              #include <fstream>
              #include <functional>
              #include <limits>
              #include <list>
              #include <map>
              #include <iomanip>
              #include <ios>
              #include <iosfwd>
              #include <iostream>
              #include <istream>
              #include <ostream>
              #include <queue>
              #include <set>
              #include <sstream>
              #include <stack>
              #include <stdexcept>
              #include <streambuf>
              #include <string>
              #include <utility>
              #include <vector>
              #include <cwchar>
              #include <cwctype>
              using namespace std;
              int a,b;
              int main()
              {
                  cin>>a>>b;
              	cout<<a+b;
                  return 0;
              }
              

              用上了所有知道的头文件

              • @ 2025-6-7 15:04:23

                允许我秀一波

                #include <windows.h>
                #include <cassert>
                #include <cctype>
                #include <cerrno>
                #include <cfloat>
                #include <ciso646>
                #include <climits>
                #include <clocale>
                #include <cmath>
                #include <csetjmp>
                #include <csignal>
                #include <cstdarg>
                #include <cstddef>
                #include <cstdio>
                #include <cstdlib>
                #include <cstring>
                #include <ctime>
                #include <ccomplex>
                #include <cfenv>
                #include <cinttypes>
                #include <cstdalign>
                #include <cstdbool>
                #include <cstdint>
                #include <ctgmath>
                #include <cuchar>
                #include <cwchar>
                #include <cwctype>
                #include <algorithm>
                #include <bitset>
                #include <complex>
                #include <deque>
                #include <exception>
                #include <fstream>
                #include <functional>
                #include <iomanip>
                #include <ios>
                #include <iosfwd>
                #include <iostream>
                #include <istream>
                #include <iterator>
                #include <limits>
                #include <list>
                #include <locale>
                #include <map>
                #include <memory>
                #include <new>
                #include <numeric>
                #include <ostream>
                #include <queue>
                #include <set>
                #include <sstream>
                #include <stack>
                #include <stdexcept>
                #include <streambuf>
                #include <string>
                #include <typeinfo>
                #include <utility>
                #include <valarray>
                #include <vector>
                #include <array>
                #include <atomic>
                #include <chrono>
                #include <codecvt>
                #include <condition_variable>
                #include <forward_list>
                #include <future>
                #include <initializer_list>
                #include <mutex>
                #include <random>
                #include <ratio>
                #include <regex>
                #include <scoped_allocator>
                #include <system_error>
                #include <thread>
                #include <tuple>
                #include <typeindex>
                #include <type_traits>
                #include <unordered_map>
                #include <unordered_set>
                #include <shared_mutex>
                #include <charconv>
                #include <filesystem>
                
                
              • @ 2025-8-22 9:09:37

                @

                Dev-C++正常运行

                #include <accctrl.h>
                #include <aclapi.h>
                #include <aclui.h>
                #include <adsprop.h>
                #include <adxintrin.h>
                #include <afxres.h>
                #include <algorithm>
                #include <alloca.h>
                #include <amaudio.h>
                #include <ammintrin.h>
                #include <amvideo.h>
                #include <any>
                #include <array>
                #include <assert.h>
                #include <atomic>
                #include <audevcod.h>
                #include <auto_ptr.h>
                #include <aviriff.h>
                #include <avx2intrin.h>
                #include <avx5124fmapsintrin.h>
                #include <avx5124vnniwintrin.h>
                #include <avx512bitalgintrin.h>
                #include <avx512bwintrin.h>
                #include <avx512cdintrin.h>
                #include <avx512dqintrin.h>
                #include <avx512erintrin.h>
                #include <avx512fintrin.h>
                #include <avx512ifmaintrin.h>
                #include <avx512ifmavlintrin.h>
                #include <avx512pfintrin.h>
                #include <avx512vbmi2intrin.h>
                #include <avx512vbmi2vlintrin.h>
                #include <avx512vbmiintrin.h>
                #include <avx512vbmivlintrin.h>
                #include <avx512vlbwintrin.h>
                #include <avx512vldqintrin.h>
                #include <avx512vlintrin.h>
                #include <avx512vnniintrin.h>
                #include <avx512vnnivlintrin.h>
                #include <avx512vpopcntdqintrin.h>
                #include <avx512vpopcntdqvlintrin.h>
                using namespace std;
                int main() {
                    long long a, b;
                    cin >> a >> b;
                    cout << a + b;
                    return 0;
                }
                
            • 1
              @ 2025-3-31 21:40:36

              声明:后几种方法一般不用

              C++题解

              这里采用多种方法求解。

              方法一

              读入a和b,输出a+b。

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

              如果你看不懂上面的代码,那你可以看看下面的。

              #include <bits/stdc++.h>
              using namespace std;
              
              #define 开始啦 main()
              #define 开头 {
              #define 结尾 }
              #define 和 , 
              #define 没了 return 0
              #define 整数32位 int
              #define 输入 cin
              #define 输出 cout 
              #define 一个 >> 
              #define 这个 <<
              #define 加上 +
              #define 换行 '\n' 
              
              整数32位 开始啦
              开头
              	整数32位 a 和 b;
              	输入 一个 a 一个 b;
              	输出 这个 a 加上 b 这个 换行; 
              	没了;
              结尾
              

              方法二

              数手指都会吧,我们就用“数手指”的方法做这一题。

              #include <bits/stdc++.h>
              using namespace std;
              
              int a, b, ans = 0;
              
              int main() {
              	scanf("%d%d", &a, &b);
              	for (int i = 1; i <= a; i++)
              		ans++;
              	for (int j = 1; j <= b; j++)
              		ans++;
              	printf("%d\n", ans);
              	return 0;
              }
              

              方法三

              算法数据结构的角度来思考一下这一题……

              我们可以设计一个这样的算法:先将a和b插入到一个数据结构(栈、队列或堆)中,非空时,将头上的元素取出,如果大于1则拆成它减1和1(根据自己的喜好)再插入,否则统计答案。

              写法

              #include <bits/stdc++.h>
              using namespace std;
              
              int a, b, ans = 0;
              stack<int> s;
              
              int main() {
              	scanf("%d%d", &a, &b);
              	s.push(a);
              	s.push(b);
              	while (!s.empty()) {
              		int x = s.top();
              		s.pop();
              		if (x > 1) {
              			s.push(x - 1);
              			s.push(1);
              		}
              		else
              			ans += x; 
              	}
              	printf("%d\n", ans);
              	return 0;
              }
              

              队列写法

              #include <bits/stdc++.h>
              using namespace std;
              
              int a, b, ans = 0;
              queue<int> q;
              
              int main() {
              	scanf("%d%d", &a, &b);
              	q.push(a);
              	q.push(b);
              	while (!q.empty()) {
              		int x = q.front();
              		q.pop();
              		if (x > 1) {
              			q.push(x - 1);
              			q.push(1);
              		}
              		else
              			ans += x; 
              	}
              	printf("%d\n", ans);
              	return 0;
              }
              

              写法

              #include <bits/stdc++.h>
              using namespace std;
              
              int a, b, ans = 0;
              priority_queue<int> h;
              
              int main() {
              	scanf("%d%d", &a, &b);
              	h.push(a);
              	h.push(b);
              	while (!h.empty()) {
              		int x = h.top();
              		h.pop();
              		if (x > 1) {
              			h.push(x - 1);
              			h.push(1);
              		}
              		else
              			ans += x; 
              	}
              	printf("%d\n", ans);
              	return 0;
              }
              

              方法四

              我们可以使用高精度加法。

              #include <bits/stdc++.h>
              using namespace std; 
              
              char s1[100], s2[100];
              int a[100], b[100], c[100];
              
              int main() {
                  scanf("%s%s", s1 + 1, s2 + 1);
                  int la = strlen(s1 + 1), lb = strlen(s2 + 1), lc;
                  lc = max(la, lb);
              	for (int i = 1; i <= la; i++)
              		a[i] = s1[la - i + 1] - '0';
              	for (int i = 1; i <= lb; i++)
              		b[i] = s2[lb - i + 1] - '0';
              	memset(c, 0, sizeof(c));
              	for (int i = 1; i <= lc; i++) {
              		c[i] += a[i] + b[i];
              		c[i + 1] = c[i] / 10;
              		c[i] %= 10;
              	}
              	if (c[lc + 1] > 0)
              		lc++;
              	for (int i = lc; i >= 1; i--)
              		printf("%d", c[i]);
              	printf("\n");
              	return 0;
              }
              

              方法五

              方法三方法四结合。

              #include <bits/stdc++.h>
              using namespace std;
              
              int a, b, c[100], lc = 1;
              priority_queue<int> h;
              
              int main() {
              	scanf("%d%d", &a, &b);
              	h.push(a);
              	h.push(b);
              	memset(c, 0, sizeof(c));
              	while (!h.empty()) {
              		int x = h.top();
              		h.pop();
              		if (x > 1) {
              			h.push(x - 1);
              			h.push(1);
              		}
              		else {
              			c[1] += x;
              			for (int i = 1; i <= lc; i++) {
              				c[i + 1] += c[i] / 10;
              				c[i] %= 10;
              			}
              			if (c[lc + 1] > 0)
              				lc++;
              		}
              	}
              	for (int i = lc; i >= 1; i--)
              		printf("%d", c[i]);
              	printf("\n");
              	return 0;
              }
              

              你竟然认真的看完了!

              恭喜你,把简单的问题复杂化了!要是你真的看懂了,就说明你太没事闲的了

              • 1
                @ 2025-3-27 6:01:40

                此题求两数之和用 + 号,但我们可以用 sum 函数直接求和。 用Python写最简题解如下:

                print(sum(list(map(int,input().split()))))
                
                • 1
                  @ 2025-3-12 12:54:38

                  一道简单的入门测试题。

                  头文件 <iostream> <bits/stdc++.h>均可。

                  #include<iostream>
                  using namespace std;
                  int main()
                  {
                  	int a,b;
                  	cin>>a>>b;
                  	cout<<a+b;
                  	
                  	return 0;
                  }
                  
                  #include<bits/stdc++.h>
                  using namespace std;
                  int main()
                  {
                  	int a,b;
                      scanf("%d%d",&a,&b);
                  	printf("%d\n",a+b);
                  	
                  	return 0;
                  }
                  
                  • 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-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;
                      }
                      
                      • 1
                        @ 2021-4-24 8:53:55

                        我来写一个Python题解。

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

                        不得不说Python是真心简单

                        • 0
                          @ 2025-10-26 10:28:05

                          #include<stdio.h>

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

                          • 0
                            @ 2025-10-22 18:38:53
                            #include <bits/stdc++.h>
                            using namespace std;
                            int a,b;
                            int main() 
                            {
                                cin>>a>>b;
                                cout<<a+b;
                                return 0;
                            }
                            
                            • 0
                              @ 2025-10-18 11:26:52

                              一道经典却s*的高级语言入门题。

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

                              Information

                              ID
                              56
                              Time
                              1000ms
                              Memory
                              1024MiB
                              Difficulty
                              1
                              Tags
                              # Submissions
                              12148
                              Accepted
                              5498
                              Uploaded By