题解 | #Primary Arithmetic#

Primary Arithmetic

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

#include <iostream>

using namespace std;

int main() {
    string x, y;
    while (cin >> x >> y) {
        if (x == "0" && y == "0") break;
        else {
            int res = 0, t = 0;
            for (int i = x.size() - 1, j = y.size() - 1; i >= 0 || j >= 0; i--, j--) {
                if (i >= 0) t += x[i] - '0';
                if (j >= 0) t += y[j] - '0';
                t /= 10; //向高位进位
                if (t > 0) {
                    res++;//记录进位次数
                }
            }
            if (res == 0) cout << "NO carry operation." << endl;
            else if (res == 1) cout << "1 carry operation." << endl;
            else cout << res << " carry operations." << endl;
        }
    }
    return 0;
}

全部评论

相关推荐

09-23 14:45
贵州大学 财务
勇敢求职牛牛:怎么9.2佬人手一个中信证券实习
点赞 评论 收藏
分享
牛客21331815...:像我一投就pass,根本不用焦虑泡池子
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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