9.14 百度B卷前两题AC(CPP版本)

1.倒转乘法表
#include <bits/stdc++.h>

using namespace std;

int rev(int in) {
    int out = 0;
    while (in) {
        out = out * 10 + in % 10;
        in /= 10;
    }
    return out;
}


int main () {
    int N, K;
    cin >> N >> K;
    int ret = 0;
    for (int i = 1; i <= K; i++) {
        int cur = rev(N * i);
        if (cur > ret) ret = cur;
    }
    cout << ret << endl;
    return 0;
}
2.共同区间
#include <bits/stdc++.h>

using namespace std;


int main () {
    string str;
    cin >> str;
    int l = 0, r = str.size() - 1;
    int lc = l, rc = r;
    while (l < rc && str[l] != str[rc]) rc--;
    while (lc < r && str[lc] != str[r]) lc++;
    if (rc - l < r - lc) {
        cout << lc + 1 << " " << r << " " << lc + 2 << " " << r + 1 << endl;
    } else {
        cout << l + 1 << " " << rc << " " << l + 2 << " " << rc + 1 << endl;
    }
    return 0;
}



#百度笔试##百度##笔经#
全部评论
就只有两道题?
点赞 回复 分享
发布于 2022-10-22 17:31 山西

相关推荐

评论
点赞
2
分享

创作者周榜

更多
牛客网
牛客企业服务