提交时间:2024-10-04 14:16:45
运行 ID: 33098
#include <cstdio> #include <iostream> #include <algorithm> using namespace std; string n; int main() { cin >> n; if (n.size() == 1) { cout << "9" << endl; return 0; } int k = n[0] - '0'; n[0] = '9'; for (int i = 1; i < n.size(); i++) { int w = n[i] - '0'; w = (w + 9 - k) % 10; n[i] = w + '0'; } int c = 1; while (c < n.size() && n[c] == '9') c++; if (c < n.size()) n[c]++; cout << n << endl; return 0; }