就错一个
2024-02-24 21:45:35
发布于:浙江
5阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int charToNum(char c) {
return c - 'A';
}
char numToChar(int num) {
return num + 'A';
}
string f(string num1, string num2) {
string result;
int carry = 0;
int len1 = num1.length();
int len2 = num2.length();
int i = len1 - 1;
int j = len2 - 1;
while (i >= 0 || j >= 0 || carry > 0) {
int digit1 = (i >= 0) ? charToNum(num1[i]) : 0;
int digit2 = (j >= 0) ? charToNum(num2[j]) : 0;
int sum = digit1 + digit2 + carry;
carry = sum / 20;
int remainder = sum % 20;
result = numToChar(remainder) + result;
i--;
j--;
}
return result;
}
int main() {
string num1, num2;
cin >> num1 >> num2;
string sum = f(num1, num2);
cout << sum << endl;
return 0;
}
这里空空如也
有帮助,赞一个