/*题目描述
请设计一个算法能够完成两个用字符串存储的整数进行相加操作,对非法的输入则返回error
输入描述:
输入为一行,包含两个字符串,字符串的长度在[1,100]。
输出描述:
输出为一行。合法情况输出相加结果,非法情况输出error
示例1
输入
123 123
abd 123
输出
246
error
*/
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
int main() {
char one[101], two[101], swap[101];
int One[102] = { 0 }, Two[102] = { 0 }, Swap[102] = { 0 };
//防止发生意外
memset(one, '\0', sizeof(char) * 101);
memset(two, '\0', sizeof(char) * 101);
memset(swap, '\0', sizeof(char) * 101);
cin >> one;
cin>> two;
int len_one = 0, len_two = 0, len = 0;
len_one = strlen(one);
len_two = strlen(two);
if (len_one > len_two) {
strcpy(swap,one);
strcpy(one, two);
strcpy(two, swap);
}
len_one = strlen(one);
len_two = strlen(two);
for (int i = 0; i < len_one; i++) {
if (!(one[i] >= '0'&&one[i] <= '9')) {
cout << "Error" << endl;
exit(0);
}
One[i] = one[len_one - 1 - i] - '0';
}
for (int k = 0; k < len_two; k++) {
if (!(two[k] >= '0'&&two[k] <= '9')) {
cout << "Error" << endl;
exit(0);
}
Two[k] = two[len_two-k-1] - '0';
}
for (int j = 0; j < len_one; j++) {
Two[j] += One[j];
if (Two[j] > 9) {
Two[j] -= 10;
Two[j + 1] += 1;
}
}
bool judge = false;
for (int x = len_two+1; x >= 0; x--) {
if (Two[x] != 0) {
judge = true;
}
if (judge) {
cout << Two[x];
}
}
cout << endl;
return 0;
}