This is obviously a greedy strategy, but the sorting algorithm has not been written, it takes me a few hours. Later found that there is a blog http://ppcool.iteye.com/blog/1731427 in the sort of good simple ah, well affected. Go back to the dormitory and continue to lick the wound.
/* * pat_1038.cpp */#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define N10010struct Node {char str[10];};bool operator<( Node const& a, Node const& b ){if ( strcmp( a.str, b.str ) == 0 )return true;int al, bl, i;al = strlen(a.str);bl = strlen(b.str);for ( i = 0; i < al && i < bl && a.str[i] == b.str[i]; ++ i );if ( strcmp( a.str, b.str ) < 0 ) {if ( i < al ) return true;if ( strcmp(a.str, b.str+i) <= 0 ) return true;return false;}else {if ( i < bl )return false;if ( strcmp( a.str+i, b.str ) > 0 )return false; return true;}}Node number[N];int n;int main(){int i, k;char str[10];while ( scanf("%d", &n ) != EOF && n ) {for ( i = 0; i < n; ++ i ) {scanf(" %s", number[i].str );}sort( number, number+n );k = 0;while ( k < n ) {for ( i = 0; i < strlen(number[k].str) && '0' == number[k].str[i]; ++ i );if ( i < strlen( number[k].str ) ) {printf("%s", number[k].str+i );break;}++ k;}if ( k >= n )printf("0\n");else {for ( i = k+1; i < n; ++ i )printf("%s", number[i].str );}}return 0;}