解题思路:
注意事项:
参考代码:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<int> add (vector<int> &p1, vector<int> &p2)
{
vector<int> temp;
int t = 0;
for (int i = 0; i < p1.size() || i < p2.size(); i++)
{
if (i < p1.size()) t += p1[i];
if (i < p2.size()) t += p2[i];
temp.push_back ((t + 10) % 10);
t /= 10;
}
if (t) temp.push_back(1);
return temp;
}
int main()
{
string a, b;
cin >> a >> b;
vector<int> p1, p2, temp;
for (int i = a.size() - 1; i >= 0; i--) p1.push_back(a[i] - '0');
for (int i = b.size() - 1; i >= 0; i--) p2.push_back(b[i] - '0');
temp = add (p1, p2);
for (int i = temp.size() - 1; i >= 0; i--) printf ("%d", temp[i]);
return 0;
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题8.9 (C语言代码)浏览:570 |
九宫重排 (C++代码)浏览:1334 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:541 |
printf基础练习2 (C语言代码)浏览:305 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:751 |
【蟠桃记】 (C语言代码)浏览:664 |
局部变量作函数返回值的问题浏览:981 |
IP判断 (C语言代码)浏览:539 |
Tom数 (C语言代码)浏览:555 |
妹子杀手的故事 (C语言代码)浏览:1054 |