#include <iostream> #include <cstdio> using namespace std; int main() { ios::sync_with_stdio(false); size_t N; cin >> N; size_t* arr = new size_t[N]; for (size_t i = 0 ; i < N ; ++i) cin >> arr[i]; size_t count = 0; for (size_t i = 1 ; i < N ; ++i) { if (arr[i] > arr[i-1]) continue; while (arr[i] <= arr[i-1]) { arr[i] *= 10; ++count; if ((arr[i-1] - arr[i]) < 9) { arr[i] = arr[i-1]+1; break; } } } cout << count; delete [] arr; }
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 | #include <iostream> #include <cstdio> using namespace std; int main() { ios::sync_with_stdio(false); size_t N; cin >> N; size_t* arr = new size_t[N]; for (size_t i = 0 ; i < N ; ++i) cin >> arr[i]; size_t count = 0; for (size_t i = 1 ; i < N ; ++i) { if (arr[i] > arr[i-1]) continue; while (arr[i] <= arr[i-1]) { arr[i] *= 10; ++count; if ((arr[i-1] - arr[i]) < 9) { arr[i] = arr[i-1]+1; break; } } } cout << count; delete [] arr; } |