#include <bits/stdc++.h>
using namespace std;
#define LL long long
bool czy(string a, string b)
{
if(a.size()>b.size())
return true;
if(a.size()<b.size())
return false;
int n = a.size();
for(int i=0; i<n; i++)
{
if(a[i]>b[i])
{
return true;
}
if(a[i]<b[i])
return false;
}
return false;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
string r;
string ost = "0";
LL w = 0;
for(int i=0; i<n; i++)
{
cin>>r;
if(!czy(r, ost))
{
string cos = ost.substr(0, r.size());
if(cos==r)
{
if(ost.size()==r.size())
{
r+="0";
w++;
}
else
{
if(ost[ost.size()-1]=='9')
{
for(int j=r.size(); j<ost.size()-2; j++)
{
r+=ost[j];
w++;
}
char x = char(ost[ost.size()-2]+1);
if(ost[ost.size()-2]=='9')
x = '0';
r+=x;
r+="0";
w+=2;
}
else
{
for(int j=r.size(); j<ost.size()-1; j++)
{
r+=ost[j];
w++;
}
r+=char(ost[ost.size()-1]+1);
w++;
}
}
}
else
{
int x = ost.size() - r.size();
for(int i=0; i<x; i++)
{
r+="0";
}
if(!czy(r, ost))
{
x++;
r+="0";
}
w+=x;
}
}
ost = r;
}
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 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 85 86 87 88 89 90 91 92 93 94 95 | #include <bits/stdc++.h> using namespace std; #define LL long long bool czy(string a, string b) { if(a.size()>b.size()) return true; if(a.size()<b.size()) return false; int n = a.size(); for(int i=0; i<n; i++) { if(a[i]>b[i]) { return true; } if(a[i]<b[i]) return false; } return false; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; string r; string ost = "0"; LL w = 0; for(int i=0; i<n; i++) { cin>>r; if(!czy(r, ost)) { string cos = ost.substr(0, r.size()); if(cos==r) { if(ost.size()==r.size()) { r+="0"; w++; } else { if(ost[ost.size()-1]=='9') { for(int j=r.size(); j<ost.size()-2; j++) { r+=ost[j]; w++; } char x = char(ost[ost.size()-2]+1); if(ost[ost.size()-2]=='9') x = '0'; r+=x; r+="0"; w+=2; } else { for(int j=r.size(); j<ost.size()-1; j++) { r+=ost[j]; w++; } r+=char(ost[ost.size()-1]+1); w++; } } } else { int x = ost.size() - r.size(); for(int i=0; i<x; i++) { r+="0"; } if(!czy(r, ost)) { x++; r+="0"; } w+=x; } } ost = r; } cout<<w; } |
English