Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. #include <algorithm>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <string>
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. int N;
  10. string V[ 100001 ];
  11. int brojac;
  12.  
  13. int toint ( char A ) {
  14.     if ( A == '0' ) return 0;
  15.     if ( A == '1' ) return 1;
  16.     if ( A == '2' ) return 2;
  17.     if ( A == '3' ) return 3;
  18.     if ( A == '4' ) return 4;
  19.     if ( A == '5' ) return 5;
  20.     if ( A == '6' ) return 6;
  21.     if ( A == '7' ) return 7;
  22.     if ( A == '8' ) return 8;
  23.     if ( A == '9' ) return 9;
  24. }
  25.  
  26. bool cmp ( string A, string B ) {
  27.      if ( A.size() != B.size() ) {
  28.         return A.size() < B.size();
  29.      }
  30.      for ( int i = 0 ; i < A.size() ; ++i ) {
  31.          if ( A[ i ] != B[ i ] ) {
  32.             return toint ( A[ i ] ) < toint ( B[ i ] );
  33.          }
  34.      }
  35. }
  36.  
  37. int main() {
  38.     scanf ( "%d", &N );
  39.     for ( int i = 0 ; i < N ; ++i ) {
  40.         char arr[ 101 ];
  41.         scanf ( "%s", arr );
  42.         for ( int j = 0 ; j < strlen ( arr ) ; ++j ) {
  43.             if ( isdigit ( arr[ j ] ) ) {
  44.                V[ brojac ] += arr[ j ];
  45.             }
  46.             else {
  47.                  ++brojac;
  48.             }
  49.         }
  50.         ++brojac;
  51.     }            
  52.     sort ( V, V + brojac, cmp );
  53.     for ( int i = 0 ; i < brojac ; ++i ) {
  54.         if ( V[ i ] != "" ) {
  55.            for ( int j = 0 ; j < V[ i ].size() ; ++j ) {
  56.                if ( V[ i ].substr ( 0, 1 ) == "0" ) {
  57.                   V[ i ].erase ( 0, 1 );
  58.                }
  59.                else {
  60.                     goto here;
  61.                }
  62.            }
  63.            here: ;
  64.            cout << V[ i ] << endl;
  65.         }
  66.     }            
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement