Editorial for Bảng thông tin điện tử
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Lưu ý: Các code mẫu dưới đây chỉ mang tính tham khảo và có thể không AC được bài tập này
Code mẫu của ladpro98
#include <iostream> #include <algorithm> #define FOR(i, a, b) for(int i = (a); i < (b); ++i) #define REP(i, a, b) for(int i = (a); i <=(b); ++i) using namespace std; int n; long long t; string toString(long long x) { string ret; while (x > 0) { ret = char('0' + x % 10) + ret; x /= 10; } return ret; } int main() { cin >> n >> t; long long cnt = 9, length = 0, power = 1; REP(digit, 1, 15) { long long newLength = length + cnt * digit; if (newLength >= t) { long long tail = t - length; long long number = power + tail / digit; long long pos = tail % digit; if (pos == 0) { --number; pos = digit - 1; } else { --pos; } string ans; ans = toString(number); ans = ans.substr(0, pos + 1); for (long long i = number - 1; i > 0; --i) { ans = toString(i) + ans; if (ans.length() >= n) { ans = ans.substr(ans.length() - n, n); break; } } cout << ans << endl; break; } length = newLength; cnt *= 10; power *= 10; } return 0; }
Comments