UVA-10905
Children ' s Game
Time Limit: 3000MS |
|
Memory Limit: Unknown |
|
64bit IO Format: %lld &%llu |
Submit Status
Description
4th Iiuc inter-university programming Contest, 2005 |
A |
Children ' s Game |
Input:standard input Output:standard output |
Problemsetter: Md. Kamruzzaman |
There is lots of number games for children. These games is pretty easy-to-play but not so easy-to-make. We'll discuss about a interesting game here. 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 is 4 integers as 123, 124,, and the following integers can be made–1231245690, 1241235690, 5612 312490, 9012312456, 9056124123 etc. In fact such integers can is made. But one thing are sure that 9056124123 are the largest possible integer which can be made.
Think that it's very easy-to-find out the the answer but would it is easy for a child who had just got the idea of numb Er?
Input
Each of the input starts with a positive integer N (≤50). In next lines there is N positive integers. Input is terminated by N = 0, which should isn't be processed.
Output
For each of the input set, you had 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 the 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 Design:: 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's good to find the right sorting 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; ' + ' represents the connection of A and B}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;}
Uva-10905-children ' s Game (simple sort)