# Pat 1038 recover the smallest number

Source: Internet
Author: User

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;}`
Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.