11725 - License 2   

Description

There are N licenses. Each license has a four-digit integer, each digit between 1 to 9. For example, if N=7, the input may look like

7

1324

5566

3578

4123

5656

4312

9847

We want to get the licenses that use the same digits and print the license appearing first. For example, 1324, 4123, and 4312 are the combination of the same digits (1, 2, 3, and 4), that is, of the same group. We want to get 1324. Similarly, 5566 and 5656 are the combination of the same digits (5, 5, 6, and 6). We want to get 5566. 

For output, we list the corresponding licenses in an increasing order line by line, so the output will look 

1324

5566


<Hint>

Reference algorithm:

Note: It is absolutely fine if you don't follow this template.  

0. Create a character array (char str[5];) for storing the input integers and create three arrays:

    0.1 int HIT[10000]={0}; to record the occurrences of the representative number of each group. 

    0.2 int FIRST[10000]={0}; to record the first showing number of each group. 

    0.3 int PRINT[10000]={0}; to judge which numbers to print.

1. Read the number of input integers and store it in variable N (scanf("%d", &N);).

2. For each of the next N integers, do 

    2.1 Read the four-digit integer and store it as a four-character string in str.

    2.2 Convert the read string in str to an integer p.

    2.3 Use the bubble sort algorithm to sort the four characters in str.

    2.4 Convert the sorted string to an integer m and do HIT[m]++;

    2.5 If HIT[m] is equal to 1, FIRST[m]=p.

    2.6 If HIT[m] is equal to 2, PRINT[FIRST[m]]=1.

3. Check each element of PRINT array; if the element of PRINT is equal to 1, print the corresponding integer.

 

The bubble sort algorithm:

/* Using bubble sort to rearrange an array A[n] */

for (i = n; i > 0; i--) {

   for (j = 1; j < i; j++) {

      if (A[j-1] > A[j]) {

         /* swap A[j-1] A[j] */

      }

   }

}

Input

The first line contains a number N (1<=N<=2000).

The next N lines provide the N four-digit integers.

Output

Each line shows the corresponding integer as explained in the problem description.

Remember to print a newline at the end of each line.

Sample Input  Download

Sample Output  Download

Tags




Discuss