#include <iostream> #include <algorithm> #include <tuple> uint32_t n_of_digits(uint32_t n) { if (0ul <= n && n < 10ul) return 1; else if (10ul <= n && n < 100ul) return 2; else if (100ul <= n && n < 1000ul) return 3; else if (1000ul <= n && n < 10000ul) return 4; else if (10000ul <= n && n < 100000ul) return 5; else if (100000ul <= n && n < 1000000ul) return 6; else if (1000000ul <= n && n < 10000000ul) return 7; else if (10000000ul <= n && n < 100000000ul) return 8; else if (100000000ul <= n && n < 1000000000ul) return 9; else return 10; } uint32_t ten_to_nth(uint32_t d) { switch (d) { case 0: return 1ul; case 1: return 10ul; case 2: return 100ul; case 3: return 1000ul; case 4: return 10000ul; case 5: return 100000ul; case 6: return 1000000ul; case 7: return 10000000ul; case 8: return 100000000ul; default: return 1000000000ul; }; } int main(int argc, char** argv) { uint32_t n = 0; std::cin >> n; uint32_t next = 0; std::cin >> next; uint64_t total_zeros = 0; uint32_t prev = next; uint32_t prev_digits = n_of_digits(prev); uint32_t prev_zeros = 0; for (uint32_t idx = 1; idx < n; idx++) { std::cin >> next; uint32_t next_digits = n_of_digits(next); uint32_t prev_complement = prev * ten_to_nth(std::max(prev_digits, next_digits) - prev_digits); uint32_t next_complement = next * ten_to_nth(std::max(prev_digits, next_digits) - next_digits); prev = next; prev_zeros = std::max(0, (int32_t)prev_digits + (int32_t)prev_zeros - (int32_t)next_digits); prev_digits = next_digits; if (prev_complement >= next_complement) prev_zeros += 1; total_zeros += prev_zeros; } std::cout << total_zeros << std::endl; return 0; }
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 | #include <iostream> #include <algorithm> #include <tuple> uint32_t n_of_digits(uint32_t n) { if (0ul <= n && n < 10ul) return 1; else if (10ul <= n && n < 100ul) return 2; else if (100ul <= n && n < 1000ul) return 3; else if (1000ul <= n && n < 10000ul) return 4; else if (10000ul <= n && n < 100000ul) return 5; else if (100000ul <= n && n < 1000000ul) return 6; else if (1000000ul <= n && n < 10000000ul) return 7; else if (10000000ul <= n && n < 100000000ul) return 8; else if (100000000ul <= n && n < 1000000000ul) return 9; else return 10; } uint32_t ten_to_nth(uint32_t d) { switch (d) { case 0: return 1ul; case 1: return 10ul; case 2: return 100ul; case 3: return 1000ul; case 4: return 10000ul; case 5: return 100000ul; case 6: return 1000000ul; case 7: return 10000000ul; case 8: return 100000000ul; default: return 1000000000ul; }; } int main(int argc, char** argv) { uint32_t n = 0; std::cin >> n; uint32_t next = 0; std::cin >> next; uint64_t total_zeros = 0; uint32_t prev = next; uint32_t prev_digits = n_of_digits(prev); uint32_t prev_zeros = 0; for (uint32_t idx = 1; idx < n; idx++) { std::cin >> next; uint32_t next_digits = n_of_digits(next); uint32_t prev_complement = prev * ten_to_nth(std::max(prev_digits, next_digits) - prev_digits); uint32_t next_complement = next * ten_to_nth(std::max(prev_digits, next_digits) - next_digits); prev = next; prev_zeros = std::max(0, (int32_t)prev_digits + (int32_t)prev_zeros - (int32_t)next_digits); prev_digits = next_digits; if (prev_complement >= next_complement) prev_zeros += 1; total_zeros += prev_zeros; } std::cout << total_zeros << std::endl; return 0; } |