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; }