求助!
http://noi.openjudge.cn/ch0106/10/高精度加法
老师过了,我过不了:(
请问哪里错了
#include <iostream>
using namespace std;
string s1,s2;
int a,b,c;
int lena,lenb,lenc;
int main()
{
cin >> s1 >> s2;
lena = s1.length();
lenb = s1.length();
for(int i = 1;i <= lena;i++)
{
a = s1 - '0';
}
for(int i = 1;i <= lenb;i++)
{
b = s2 - '0';
}
int m = 0;
lenc = lena;
if(lenb > lenc)
{
lenc = lenb;
}
for(int i = 1;i <= lenc;i++)
{
c = (m + a + b) % 10;
m = (m + a + b) / 10;
}
if(m == 1)
{
lenc++;
c = 1;
}
while(c == 0 && lenc > 1)
{
lenc--;
}
for(int i = lenc;i >= 1;i--)
{
cout << c;
}
} 参考一下吧:
https://cloud.tencent.com/developer/article/1091473?from=14588
页:
[1]