题解 | A+B

A+B

https://www.nowcoder.com/practice/b183eac8dfba4de99d47c1ca4ce9571f

#include <iostream>
using namespace std;



int main() {
    string s, s1, s2;
    while (getline(cin,s)) { // 注意 while 处理多个 case
        
        bool secondnum = false;
        char a[12] = {0}, b[12] = {0};
        //提取两个数字
        for (int i = 0, j = 0, k = 0; i < s.length(); i++) {
         
            if (s[i] == ' ')secondnum = true;
            if (s[i] == ',')continue;
            if (!secondnum) {
                a[j++] = s[i];
            } else {
                b[k++] = s[i];
            }
        }
        int anum=stoi(a);
        int bnum=stoi(b);
        printf("%d\n", anum+bnum);
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

哞客37422655...:你猜为什么福利这么好还得一直追着你问
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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