题解 | #A+B#
A+B
https://www.nowcoder.com/practice/b183eac8dfba4de99d47c1ca4ce9571f
// 利用string的erase删除',',只保留纯数字,然后再利用stoi函数将字符串转为数字,直接进行相加 #include "iostream" #include "string" using namespace std; int main(){ string str1, str2; while(cin >> str1 >> str2){ while(1){ int pos1 = str1.find(','), pos2 = str2.find(','); if(pos1 == string::npos && pos2 == string::npos) break; if(pos1 != string::npos) str1.erase(pos1, 1); if(pos2 != string::npos) str2.erase(pos2, 1); } cout << stoi(str1)+stoi(str2) << endl; } return 0; }