#include <iostream> #include <sstream> using namespace std; int n,x=0,d2=0,d3=0,dlug,dlug2; int a[200000]; string l,m; char z='0'; int main() { cin>>n; for(int q=0; q<n; q++) { cin>>a[q]; dlug2=0; dlug=0; d2=0; while(a[q]<=a[q-1]) { ostringstream ss; ss << a[q]; l = ss.str(); if(d2==0) dlug=l.length(); ostringstream s; s << d2; m = s.str(); if(d2==0) l=l+m; d2++; if(d2==9) { d2=0; l.replace(dlug,m.length()+1,"0"+m); dlug2=l.length(); } else { l.replace(dlug,m.length(),m); dlug2=l.length(); a[q] = atoi(l.c_str()); } } x+=dlug2-dlug; } cout<<x<<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 | #include <iostream> #include <sstream> using namespace std; int n,x=0,d2=0,d3=0,dlug,dlug2; int a[200000]; string l,m; char z='0'; int main() { cin>>n; for(int q=0; q<n; q++) { cin>>a[q]; dlug2=0; dlug=0; d2=0; while(a[q]<=a[q-1]) { ostringstream ss; ss << a[q]; l = ss.str(); if(d2==0) dlug=l.length(); ostringstream s; s << d2; m = s.str(); if(d2==0) l=l+m; d2++; if(d2==9) { d2=0; l.replace(dlug,m.length()+1,"0"+m); dlug2=l.length(); } else { l.replace(dlug,m.length(),m); dlug2=l.length(); a[q] = atoi(l.c_str()); } } x+=dlug2-dlug; } cout<<x<<endl; return(0); } |