题解 | #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;
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-02 17:58
点赞 评论 收藏
分享
06-11 13:34
门头沟学院 C++
offe从四面八方来:我真的没时间陪你闹了
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务