#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <vector> using namespace std; int nlen(long long a) { int res = 0; while(a) { res++; a /= 10; } return res; } long long check(long long a, long long b) { while (a <= b) { a *= 10; a += 9; } return a; } long long nb(long long a, long long b) { while (a <= b) { a *= 10; } return a; } long long mbp1(long long a, long long b) { long long tlen = nlen(b); while (nlen(a) < tlen) { a *= 10; } if (a > b) return a; if (a ==b) return a + 1; else return b + 1; } int main() { int n; int a; long long b; cin >> n >> a; if (n==1) { cout << 0 << endl; return 0; } b = a; int clen = nlen(b); long long res = 0; for (int i=0;i<n-1;i++) { scanf("%d", &a); int alen = nlen(a); long long na = check(a, b); int na_len = nlen(na); if (na_len > nlen(b)) { if (na_len == alen) { clen = alen; } else { clen++; } b = nb(a, b); if (na_len > 14) { b /= 10; } } else { b = mbp1(a, b); } res += (clen - alen); } cout << res << 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <vector> using namespace std; int nlen(long long a) { int res = 0; while(a) { res++; a /= 10; } return res; } long long check(long long a, long long b) { while (a <= b) { a *= 10; a += 9; } return a; } long long nb(long long a, long long b) { while (a <= b) { a *= 10; } return a; } long long mbp1(long long a, long long b) { long long tlen = nlen(b); while (nlen(a) < tlen) { a *= 10; } if (a > b) return a; if (a ==b) return a + 1; else return b + 1; } int main() { int n; int a; long long b; cin >> n >> a; if (n==1) { cout << 0 << endl; return 0; } b = a; int clen = nlen(b); long long res = 0; for (int i=0;i<n-1;i++) { scanf("%d", &a); int alen = nlen(a); long long na = check(a, b); int na_len = nlen(na); if (na_len > nlen(b)) { if (na_len == alen) { clen = alen; } else { clen++; } b = nb(a, b); if (na_len > 14) { b /= 10; } } else { b = mbp1(a, b); } res += (clen - alen); } cout << res << endl; return 0; } |