admin管理员组文章数量:1130349
链接:https://ac.nowcoder/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;
}
链接:https://ac.nowcoder/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;
}
本文标签:
版权声明:本文标题:Hello I am HERE! 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/jiaocheng/1758615364a2781923.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论