我的PAT-BASIC代码仓:https://github.com/617076674/PAT-BASIC
原题链接:https://pintia.cn/problem-sets/994805260223102976/problems/994805306310115328
题目描述:
知识点:字符串
思路:求出PA和PB,再相加即可
时间复杂度是O(n),其中n为正整数A和正整数B的位数之和。空间复杂度是O(1)。
C++代码:
#include<iostream>
#include<string>
using namespace std;
int main() {
string input1;
char num1;
string input2;
char num2;
cin >> input1 >> num1 >> input2 >> num2;
int count1 = 0;
for (int i = 0; i < input1.length(); i++) {
if (input1[i] == num1) {
count1++;
}
}
int count2 = 0;
for (int i = 0; i < input2.length(); i++) {
if (input2[i] == num2) {
count2++;
}
}
long pa = 0;
while (count1 > 0) {
pa = pa * 10 + num1 - '0';
count1--;
}
long pb = 0;
while (count2 > 0) {
pb = pb * 10 + num2 - '0';
count2--;
}
cout << (pa + pb);
return 0;
}
C++解题报告: