跳到正文

算法·理论

U325625题解

Just_Starlet约 2 分钟
原文
文章信息与版本

文章信息

发布
2023年8月10日
收录
2025年12月12日
更新
2026年11月13日
篇幅
约 2 分钟
获赞
1

版本

  1. v1当前

这一题嘛,是一个简单的A+B 问题,但是时间和空间被极度限制。
第一反应是用快读快写

C++
#include<bits/stdc++.h>
using namespace std;
void read(int &x){
	//注:此处请勿漏掉'&'
	x=0;int fl=1;
	char ch=getchar();
	while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
	if(ch=='-') fl=-1,ch=getchar();
	while(ch<='9'&&ch>='0') 
  		x=x*10+ch-'0',ch=getchar();
	x=x*fl;
}
void write(int x){
	if(x<0) x=-x,putchar('-');//输出负号
	static int sta[35];
	int top=0;
	do{
		sta[top++]=x%10;
		x/=10;
	}while(x);
	while(top) putchar('0'+sta[--top]);
	//数字从低位到高位入栈,再按顺序出栈
	//通过栈输出,可以降低复杂度
	return ;
}
int main(){
	int a,b;
	read(a),read(b);
	write(a+b);
	return 0;
}

最终结果一般,3ms3ms。
后面出题人放宽了要求
暴力也可以过了
~~我的快读快写白写了/(ㄒoㄒ)/~~~~
下面将暴力代码一并放出

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

4ms4ms过的,也行

原文