#include <bits/stdc++.h> using namespace std; int main() { string a,b; int n,d; unsigned long long w=0; bool z,m; cin>>n; cin>>b; for(int i=1; i<n; i++){ z=0; m=0; d=0; for(int i=b.length()-1; i>0; i--){ if(b[i]=='9'){ d++; }else{ break; } } cin>>a; if(a.length()<=b.length()){ for(int i=0; i<a.length(); i++){ if(a[i]>b[i]){ z=1; break; }else if(a[i]<b[i]){ m=1; break; } } while(b.length()>a.length()+1+d&&!z&&!m){ a+=b[a.length()]; w++; } if(b.length()==a.length()+1+d&&!z&&!m){ a+=char(int(b[a.length()])+1); w++; z=1; } while(b.length()>a.length()){ a+='0'; w++; } if(!z){ a+='0'; w++; } } b=a; } cout<<w; }
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 | #include <bits/stdc++.h> using namespace std; int main() { string a,b; int n,d; unsigned long long w=0; bool z,m; cin>>n; cin>>b; for(int i=1; i<n; i++){ z=0; m=0; d=0; for(int i=b.length()-1; i>0; i--){ if(b[i]=='9'){ d++; }else{ break; } } cin>>a; if(a.length()<=b.length()){ for(int i=0; i<a.length(); i++){ if(a[i]>b[i]){ z=1; break; }else if(a[i]<b[i]){ m=1; break; } } while(b.length()>a.length()+1+d&&!z&&!m){ a+=b[a.length()]; w++; } if(b.length()==a.length()+1+d&&!z&&!m){ a+=char(int(b[a.length()])+1); w++; z=1; } while(b.length()>a.length()){ a+='0'; w++; } if(!z){ a+='0'; w++; } } b=a; } cout<<w; } |