加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

大数相加

发布时间:2020-12-14 05:12:56 所属栏目:大数据 来源:网络整理
导读:1 #include bits/stdc++.h 2 using namespace std; 3 4 int main() 5 { 6 string a,b,res; 7 cin a b; 8 int i,k,inc,lena,lenb,temp; 9 lena = a.length(); lenb = b.length(); 10 for (i = lena - 1 ,k = lenb - 1 ,inc = 0 ; i = 0 || k = 0 ; --i,-- k)
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 int main()
 5 {
 6     string a,b,res;
 7     cin >> a >> b;
 8     int i,k,inc,lena,lenb,temp;
 9     lena = a.length(); lenb = b.length();
10     for (i = lena - 1,k = lenb - 1,inc = 0; i >= 0 || k >= 0; --i,--k)
11     {
12         temp = inc;
13         if (i >= 0)
14         {
15         temp += a[i] - 0;
16         }
17         if (k >= 0)
18         {
19             temp += b[k] - 0;
20         }
21         res += temp % 10 + 0;
22         inc = temp / 10;
23     }
24     if (inc)
25     {
26     res += inc + 0;
27     }
28     reverse(begin(res),end(res));
29     cout << res << endl;
30     return 0;
31 }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读