several吧 关注:12贴子:165
  • 1回复贴,共1
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.
InputThe first line of each test case contains an integer N (1 ≤ N ≤ 50), indicating the number of the players. Then N integers followed in the second line. Each number will be between 0 and 100000, inclusive.
The input is terminated with N = 0.
OutputOutput one line for each test case, indicating the winner's resulting number.
Sample Input6 1 10 100 1000 10000 100000 3 9638 8210 331 0Sample Output1 3689
答案那个大神知道?帮忙改一下下面那个也行!多谢啦!
#include<iostream>
using namespace std;
int main()
{
int n;
int s1[50],s2[6];
while(cin>>n&&n!=0)
{
for(int i=0;i<n;i++)
{
cin>>s1[i];
for(int j=0;j<6;j++) s2[j]=s1[i]%10;
for(int j=5;j>=1;j--)
{
int max=s2[0];
int maxindex=0;
for(int k=1;k<=j;k++)
{
if(max<s2[k])
{
max=s2[k];
maxindex=k;
}
}
s2[maxindex]=s2[j];
s2[j]=max;
}
s1[i]=0;
for(int j=0;j<6;j++)
{
if(s2[j>0])
s1[i]=s1[i]*10+s2[j];
}
}
int Max=s1[0];
for(int i=1;i<n;i++)
{
if(Max<s1[i])
Max=s1[i];
}
cout<<Max<<endl;
}
return 0;
}


IP属地:天津1楼2013-12-09 10:31回复


    IP属地:四川2楼2014-11-29 21:33
    回复