#include <list>
#include <string>
#include <iostream>
using namespace std;
bool operator<= ( list<char>& x, list<char>& y )
{
if ( x.size() < y.size() )
{
return true;
}
else if ( x.size() > y.size() )
{
return false;
}
else
{
auto xi = x.begin();
auto yi = y.begin();
while ( xi != x.end() )
{
if ( ( *xi ) < ( *yi ) )
{
return true;
}
else if ( ( *xi ) > ( *yi ) )
{
return false;
}
++xi;
++yi;
}
return true;
}
}
int main()
{
uint32_t N;
cin >> N;
string line;
getline( cin, line );
list<list<char>> numbers;
while ( N-- )
{
getline( cin, line );
numbers.push_back( list<char>() );
for ( const char& c : line )
{
numbers.back().push_back( c );
}
}
uint32_t m = 0U;
for ( auto ni = numbers.begin(); ni != numbers.end(); )
{
list<char>& x = *( ni++ );
list<char>& y = *ni;
if ( y <= x )
{
while ( y <= x )
{
y.push_back( '0' );
m++;
}
}
}
cout << m;
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 | #include <list> #include <string> #include <iostream> using namespace std; bool operator<= ( list<char>& x, list<char>& y ) { if ( x.size() < y.size() ) { return true; } else if ( x.size() > y.size() ) { return false; } else { auto xi = x.begin(); auto yi = y.begin(); while ( xi != x.end() ) { if ( ( *xi ) < ( *yi ) ) { return true; } else if ( ( *xi ) > ( *yi ) ) { return false; } ++xi; ++yi; } return true; } } int main() { uint32_t N; cin >> N; string line; getline( cin, line ); list<list<char>> numbers; while ( N-- ) { getline( cin, line ); numbers.push_back( list<char>() ); for ( const char& c : line ) { numbers.back().push_back( c ); } } uint32_t m = 0U; for ( auto ni = numbers.begin(); ni != numbers.end(); ) { list<char>& x = *( ni++ ); list<char>& y = *ni; if ( y <= x ) { while ( y <= x ) { y.push_back( '0' ); m++; } } } cout << m; return 0; } |
English