#include <iostream> #include <cstdint> #include <vector> #include <map> #include <array> #include <memory> namespace { using uint_t = uint_fast32_t; constexpr uint_t DEC = 10; using counters_t = std::array<uint_t, DEC>; using std::cout, std::cin; using std::vector, std::map; using std::unique_ptr, std::make_unique; uint_t digit_product(uint_t ni) { uint_t product = 1; do { product *= ni % DEC; ni /= DEC; } while (product > 0 && ni > 0); return product; } } int main() { uint_t t, ni; vector<uint_t> nis; map<uint_t, unique_ptr<counters_t>> cnts; vector<uint_fast8_t> digits = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; cin >> t; for (uint_t i = 0; i < t; ++i) { cin >> ni; nis.push_back(ni); cnts.insert({ni, make_unique<counters_t>()}); if (ni >= digits.size()) { for (uint_t j = digits.size(); j <= ni; ++j) { digits.push_back(digits[digit_product(j)]); } } } if (cnts.rbegin()->first < DEC - 1) { for (uint_t i = DEC - 1; i > cnts.rbegin()->first; --i) digits.pop_back(); } uint_t start = 1; auto prev_it = cnts.begin(); for (auto it = cnts.begin(); it != cnts.end(); ++it) { if (it != cnts.begin()) { for (uint_t j = 0; j < DEC; ++j) (*(it->second))[j] = (*(prev_it->second))[j]; } for (uint_t k = start; k <= it->first; ++k) { ++(*(it->second))[digits[k]]; } start = it->first + 1; prev_it = it; } for (uint_t i = 0; i < t; ++i) { for (uint_t j = 0; j < DEC; ++j) { cout << (*cnts[nis[i]])[j]; if (j < DEC - 1) cout << ' '; } cout << '\n'; } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | #include <iostream> #include <cstdint> #include <vector> #include <map> #include <array> #include <memory> namespace { using uint_t = uint_fast32_t; constexpr uint_t DEC = 10; using counters_t = std::array<uint_t, DEC>; using std::cout, std::cin; using std::vector, std::map; using std::unique_ptr, std::make_unique; uint_t digit_product(uint_t ni) { uint_t product = 1; do { product *= ni % DEC; ni /= DEC; } while (product > 0 && ni > 0); return product; } } int main() { uint_t t, ni; vector<uint_t> nis; map<uint_t, unique_ptr<counters_t>> cnts; vector<uint_fast8_t> digits = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; cin >> t; for (uint_t i = 0; i < t; ++i) { cin >> ni; nis.push_back(ni); cnts.insert({ni, make_unique<counters_t>()}); if (ni >= digits.size()) { for (uint_t j = digits.size(); j <= ni; ++j) { digits.push_back(digits[digit_product(j)]); } } } if (cnts.rbegin()->first < DEC - 1) { for (uint_t i = DEC - 1; i > cnts.rbegin()->first; --i) digits.pop_back(); } uint_t start = 1; auto prev_it = cnts.begin(); for (auto it = cnts.begin(); it != cnts.end(); ++it) { if (it != cnts.begin()) { for (uint_t j = 0; j < DEC; ++j) (*(it->second))[j] = (*(prev_it->second))[j]; } for (uint_t k = start; k <= it->first; ++k) { ++(*(it->second))[digits[k]]; } start = it->first + 1; prev_it = it; } for (uint_t i = 0; i < t; ++i) { for (uint_t j = 0; j < DEC; ++j) { cout << (*cnts[nis[i]])[j]; if (j < DEC - 1) cout << ' '; } cout << '\n'; } } |