1336 - Sort the String

Time Limit : 1 Second

Memory Limit : 128 MB

Submission: 59

Solved: 24

Description
You will get a lot of 0-1 string(the string only contain 0 and 1).Sort them with the length, put the less one first, if two string has the same length, put the string has less 1 first, if still tied put the one with less string value first.
Compare two string A and B:
From left to right, if the left of i-th character are all the same then compare the i-th character, if A[i] < B[i] then value of A < value of B.
e.g.
compare value 10010111 < 10011000
but compare the number of '1': 10011000 < 10010111
so 10011000 < 10010111
Input
The first line contain a number indicate how many cases.
For each case, the first line is N indicate there are N strings.
Next N line each line has a string only contain 0 and 1.
(1<=N<=1000, length of each string will less than 100)
Output
Sort and output them, one string one line.
sample input
1
6
10010010
10010111
10011000
111000000111111110000001111111000000011111110000000011110000000001000000
1100
1011
sample output
1100
1011
10010010
10011000
10010111
111000000111111110000001111111000000011111110000000011110000000001000000
hint
source
Zehua Hong
© 2015 HUST ACMICPC TEAM. All Right Reserved.