Hello I am HERE!

7 篇文章 0 订阅
6 篇文章 0 订阅
链接: https://www.nowcoder.com/acm/contest/125/C
来源:牛客网

题目描述

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

#include<bits/stdc++.h>
using namespace std;
char s1[5005],s2[5005];
int a[5005],b[5005],c[5005]={0};
int main()
{
	int t,pos;
	cin>>t;
	while(t--)
	{
		memset(c,0,sizeof(c));
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		cin>>s1>>s2;
		
		int n=strlen(s1);
		int m=strlen(s2);
		int l=m>n?m:n;
		int i,j;
		for(i=n-1;i>=0;i--)
		{
			a[n-i-1]=s1[i]-'0';
		}
		for(i=m-1;i>=0;i--)
		{
			b[m-i-1]=s2[i]-'0';
		}
		for(j=0;j<=l;j++)
		{
			c[j]+=a[j]+b[j];
			if(c[j]>9)
			{
				c[j]-=10;
				c[j+1]++;
			}
		}
		while(l--)
		{
			if(c[l]!=0)
			{
				pos=l;
				break;		
			}
		}
		for(i=pos;i>=0;i--)
		cout<<c[i];
		cout<<endl;
	}
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值