Hello I am HERE!

链接:https://ac.nowcoder.com/acm/problem/15902
来源:牛客网
 

There are many difficulties in today's contest, but this is definitely not one of them.

Because I want you to do it, the classic A+B.

 

输入描述:

First line an Integer N means n test cases.
Next 2N lines representing 2N groups of different Integers.
N<50.
THE LENGTH of every Integer will less than 5000.
All Integers will be greater than 0.
Some cases may have leading zero.

输出描述:

One line for each test cases reprecenting the answer of A+B.
Do not putout leading zero

示例1

输入

1
100000000000000
100000000000000

输出

200000000000000

备注:

You do not have to use FFT.
#include <stdio.h>
#include <cstring>
#include <algorithm>
using namespace std;
struct bign{
	int d[6000];
	int len;
	bign(){//初始化 
		memset(d,0,sizeof(d));
		len=0;
	}
};
bign change(char str[]){
	bign a;
	a.len=strlen(str);
	for(int i=0;i<a.len;i++){
		a.d[i]=str[a.len-1-i]-'0';
	}
	return a;
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		char str1[6000],str2[6000];
		scanf("%s%s",str1,str2);
		bign a=change(str1);
		bign b=change(str2);
		
		bign c;//计算求和 
		int  carry=0;
		for(int i=0;i<a.len||i<b.len;i++){
			int temp=a.d[i]+b.d[i]+carry;
			c.d[c.len++]=temp%10;
			carry=temp/10;
		}
		if(carry!=0){//进位最后不为1 
			c.d[c.len++]=carry;
		} 
		
		int j=c.len;
		for(j;j>=0;j--){//忽略掉前导0 
			if(c.d[j]!=0){
				break;
			}
		}
		for(int i=j;i>=0;i--){
			printf("%d",c.d[i]);
		}
		printf("\n");
	}
	
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值