From 5b884a06210946c5974a1751960f4689383858ef Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sat, 3 Sep 2022 20:49:00 +0800 Subject: [PATCH] =?UTF-8?q?P2602=20[ZJOI2010]=20=E6=95=B0=E5=AD=97?= =?UTF-8?q?=E8=AE=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/85802739 --- Luogu/P2602/P2602.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Luogu/P2602/P2602.cpp diff --git a/Luogu/P2602/P2602.cpp b/Luogu/P2602/P2602.cpp new file mode 100644 index 00000000..d0788669 --- /dev/null +++ b/Luogu/P2602/P2602.cpp @@ -0,0 +1,62 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +long long a, b, + f[15], g[15]{1}, + cnt_a[10], cnt_b[10]; + +std::vector gen(long long x) { + std::vector res; + + while (x) { + res.push_back(x % 10); + x /= 10; + } + + return res; +} + +void calc(long long x, long long* r) { + auto num = gen(x); + + for (int i = num.size(); i; i--) { + for (int j = 0; j < 10; j++) { + r[j] += f[i - 1] * num.at(i - 1); + } + + for (int j = 0; j < num[i - 1]; j++) { + r[j] += g[i - 1]; + } + + x -= g[i - 1] * num[i - 1]; + r[num[i - 1]] += x + 1; + r[0] -= g[i - 1]; + } +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> a >> b; + + for (int i = 1; i <= 12; i++) { + f[i] = f[i - 1] * 10 + g[i - 1]; + g[i] = g[i - 1] * 10; + } + + calc(a - 1, cnt_a); + calc(b, cnt_b); + + for (int i = 0; i < 10; i++) { + cout << cnt_b[i] - cnt_a[i] << ' '; + } + + cout << endl; + + return 0; +}