洛谷——P1601 A+B Problem(高精)

https://www.luogu.org/problem/show?pid=1601#sub

题目背景

题目描述

高精度加法,x相当于a+b problem,[b][color=red]不用考虑负数[/color][/b]

输入输出格式

输入格式:

 

分两行输入a,b<=10^500

 

输出格式:

 

输出只有一行,代表A+B的值

 

输入输出样例

输入样例#1:
1
1
输出样例#1:
2

练习
 1 #include <algorithm>
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <string>
 5 
 6 using namespace std;
 7 
 8 string str_a,str_b;
 9 int num_a[555],num_b[555],num_c[555];
10 
11 int main()
12 {
13     cin>>str_a>>str_b;
14     int len_a=str_a.length();
15     int len_b=str_b.length();
16     for(int i=0;i<len_a;i++) num_a[len_a-i]=str_a[i]-'0';
17     for(int i=0;i<len_b;i++) num_b[len_b-i]=str_b[i]-'0';
18     int len_c=1,x=0;
19     for(;len_c<=len_a||len_c<=len_b;)
20     {
21         num_c[len_c]=num_a[len_c]+num_b[len_c]+x;
22         x=num_c[len_c]/10;
23         num_c[len_c]%=10;
24         len_c++;
25     }
26     num_c[len_c]=x;
27     for(;!num_c[len_c]&&len_c>1;) len_c--;
28     for(int i=len_c;i>=1;i--) printf("%d",num_c[i]);
29     return 0;
30 }

 

转载于:https://www.cnblogs.com/Shy-key/p/7216709.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值