luogu P1601 高精度加法

 1 #include <string>
 2 #include <iostream>
 3 using namespace std;
 4 int main()
 5 {
 6     string a,b;
 7     cin >> a >> b;
 8     int x[11000] = {},y[11000] = {},z[11000] = {};
 9     for (int i = 0;i < a.length();i++)
10         x[a.length() - i] = a[i] - '0';
11     for (int i = 0;i < b.length();i++)
12         y[b.length() - i] = b[i] - '0';
13     int ad = 0,len = 1;
14     while (len <= a.length() || len <= b.length())
15     {
16         z[len] = x[len] + y[len] + ad;
17         ad = z[len] / 10;
18         z[len] = z[len] % 10;
19         len++;
20     }
21     z[len] = ad;
22     if (z[len] == 0)
23         len--;
24     for (int i = len;i >= 1;i--)
25         cout << z[i];
26 }

 

posted @ 2019-07-24 15:18  IAT14  阅读(218)  评论(0编辑  收藏  举报