UVA-10905 Children ' s Game
Time Limit: 3000MS |
|
Memory Limit: Unknown |
|
64bit IO Format: %lld &%llu |
Submit Status
Description
4thiiucinter-university Programming Contest, 2005 |
A |
Children ' s Game |
Input:standard input Output:standard Output |
problemsetter:md. Kamruzzaman |
There are lots of number games for children. These games are pretty easy to play but. We'll discuss about an interesting game. Each player would be given Npositive integer. S He can make a big integer by appending those integers after one another. Such as if there are 4 integers as 123, 124, 1241235690, then the following integers can be made–1231245690, 5612 312490, 9012312456, 9056124123 etc. In fact-such integers can be made. But One thing is sure this 9056124123 is the largest possible an integer which can be made.
You may do it ' s very easy to find out the answer but'll it is easy for a child who has just got the idea of numb Er?
Input
Each input starts with a positive integer N (≤50). In next lines there are N positive integers. The Input is terminated by N = 0 and which should is processed.
Output
For each input set, you have to print the largest possible integer which can is made by appending all the N integ ERs.
Sample Input |
Output for Sample Input |
4 123 124 56 90 5 123 124 56 90 9 5 9 9 9 9 9 0 |
9056124123 99056124123 99999 |
Source
Root:: Competitive programming 2:this increases lower bound of programming contests. Again (Steven & Felix Halim):: Data Structures and Libraries:: LINEAR data structures with built-in libraries:: c+ + STL Algorithm (Java collections)
Root:: AOAPC i:beginning algorithm Contests-training Guide (Rujia Liu):: Chapter 1. Algorithm:: General Problem Solving Techniques:: exercises:intermediate
Root:: AOAPC i:beginning algorithm Contests (Rujia Liu):: Volume 4. Algorithm design
Root:: Prominent problemsetters:: Md. Kamruzzaman (Kzaman)
Root:: Competitive programming 3:the New Lower Bound of programming contests (Steven & Felix Halim):: Data Structur Es and libraries:: LINEAR Data structures with built-in libraries:: C + + STL algorithm (Java collections)
It would be nice to find the right sort of method.
AC Code:
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
String num[55];
BOOL CMP (string A, string b)
{return
a+b > b+a; ' + ' means A and B's connection
}
int main ()
{
int n;
while (scanf ("%d", &n), N)
{for
(int i=0; i<n; i++)
{
cin >> num[i];
}
Sort (num, num+n, CMP);
for (int i=0; i<n; i++)
{
cout << num[i];
}
cout << Endl;
}
return 0;
}