9.16 OPPO 编程半知半解(CPP版本)

1.求倒序数(66.6%)
#include <bits/stdc++.h>

using namespace std;

int main () {
    string str;
    cin >> str;
    bool flag = false;
    reverse(str.begin(), str.end());
    for (const auto& c : str) if (c < '0' || c > '9') flag = true;
    long long ret = stoll(str);
    if (ret > INT_MAX || ret < INT_MIN && flag) cout << "error" << endl;
    else cout << ret << endl;
    return 0;
}
2.求折叠链表(60%)
#include <bits/stdc++.h>

using namespace std;

int main() {
    string str;
    getline(cin, str);
    vector<int> nums;
    string temp;
    for (const auto& c : str) {
        if (c <= '9' && c >= '0') {
            temp += c;
        } else {
            if (!temp.empty()) nums.push_back(stoi(temp));
            temp.clear();
        }
    }
    if (!temp.empty()) {
        nums.push_back(stoi(temp));
        temp.clear();
    }
    vector<int> out;
    string output = "[";
    int l = 0, r = nums.size() - 1;
    while (l <= r) {
        out.push_back(nums[l]);
        if (l != r) out.push_back(nums[r]);
        l++;
        r--;
    }
    for (const auto& c : out) {
        output += to_string(c) + ',';
    }
    output.pop_back();
    output += ']';
    cout << output << endl;
    return 0;
}
不太清楚异常测试用例,随便做一下了。精力有限,先写论文了。

#笔试##笔试题目##OPPO#
全部评论
***人麻了,整天笔试面试还要写论文,还要被侄女gank问初中数学题目
1 回复
分享
发布于 2021-09-16 22:54
对了,三个条件都是或
点赞 回复
分享
发布于 2021-09-16 22:53
小红书
校招火热招聘中
官网直投

相关推荐

点赞 1 评论
分享
牛客网
牛客企业服务