toj 2857. Digit Sorting

来源:互联网 发布:茶叶网络推广 编辑:程序博客网 时间:2024/04/30 11:04
Several players play a game. Each player chooses a certain number, writes it down (in decimal notation, without leading zeroes) and sorts the digits of the notation in non-decreasing order, obtaining another number. The player who receives the largest number wins.

You are given the list of numbers initially chosen by the players. Output the winner's resulting number.

Input

The first line of each test case contains an integer N (1 ≤ N ≤ 50), indicating the number of the players. ThenN integers followed in the second line. Each number will be between 0 and 100000, inclusive.

The input is terminated with N = 0.

Output

Output one line for each test case, indicating the winner's resulting number.

Sample Input

61 10 100 1000 10000 10000039638 8210 3310

Sample Output

1

3689

#include<iostream>#include<string>#include<string.h>#include<algorithm>using namespace std;int f(char *s){int r=0,l;l=strlen(s);for(int i=0;i<l-1;i++){if(s[i]!='0'){r=r+s[i]-'0';r=r*10;}}r=r+s[l-1]-'0';return r;}int main(){char s1[100000];int l1,l2,n,sum=0,N;while(cin>>N&&N){sum=0;while(N--){cin>>s1;l1=strlen(s1);sort(s1,s1+l1);n=f(s1);//cout<<n<<endl;if(n>sum)sum=n;}cout<<sum<<endl;}return 0;}


0 0
原创粉丝点击