题解 | 不要三句号的歪

不要三句号的歪

https://www.nowcoder.com/practice/7cbb7d96fb354f7995d9af1ccf8906b4

#include <iostream>
#include<vector>

using namespace std;
#define int long long
vector<int> sub(vector<int>& A, vector<int>& B) {
    vector<int> C;
    for (int i = 0, t = 0; i < A.size(); i ++ ) {
        t = A[i] - t;
        if (i < B.size()) t -= B[i];
        C.push_back((t + 10) % 10);
        if (t < 0) t = 1;
        else t = 0;
    }
    while (C.size() > 1 && C.back() == 0) C.pop_back();
    return C;
}

signed main() {
    string s;
    cin >> s;
    int i = 0;
    vector<int> a, b;
    int res1 = 0, res2 = 0, res3 = 0;
    while (s[i] != ',') {
        res1 = res1 * 10 + s[i] - '0';
        i++;

    }
    i++;
    while (s[i] != ',') {
        res2 = res2 * 10 + s[i] - '0';
        i++;
        a.push_back(s[i]);
    }
    i++;
    while (s[i] == '.') {
        i++;

    }
    i++;
    while (s[i] >= '0' && s[i] <= '9' && i < s.length()) {
        res3 = res3 * 10 + s[i] - '0';
        // b.push_back(s[i]);
        i++;

    }

    cout<<res3-res2-1;
    return 0;
}
// 64 位输出请用 printf("%lld")

本来是想用高精度,但是只有20位,用longlong就可以了,判断第三个数字和第二个数字,输出第三个数字-第二个数字-1即可。

活动地址https://www.nowcoder.com/discuss/726480854079250432

#牛客春招刷题训练营#
全部评论

相关推荐

12-15 14:16
门头沟学院 Java
回家当保安:发offer的时候会背调学信网,最好不要这样。 “27届 ”和“28届以下 ”公司招聘的预期是不一样的。
实习简历求拷打
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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