#K33157. Packet Processing Challenge

    ID: 25025 Type: Default 1000ms 256MiB

Packet Processing Challenge

Packet Processing Challenge

You are given an integer \(n\) and \(n\) data packets represented as strings. Your task is to process these packets by performing the following operations:

  • Remove duplicates: If a packet appears more than once (exact string match), consider it only once.
  • Sort each packet: For each unique packet, rearrange its characters in increasing order (i.e. sort the characters in lexicographical order). For example, the sorted version of "banana" is "aaabnn".
  • Sort the results: Finally, output the sorted packets in lexicographical order.

For instance, if the input is:

5
apple
banana
apple
cherry
banana

After removing duplicates, the unique packets are "apple", "banana", and "cherry". Sorting each one gives "aelpp", "aaabnn", and "cehrry". Sorting these results lexicographically produces:

aaabnn
 aelpp
 cehrry

Note: All input should be read from stdin and output should be printed to stdout.

inputFormat

The input is given in the following format from stdin:

  1. The first line contains an integer \(n\), representing the number of data packets.
  2. The next \(n\) lines each contain a data packet (a string without spaces).

outputFormat

Output the processed packets to stdout, each on a separate line. The output should consist of the unique packets (after processing) in lexicographical order.

## sample
5
apple
banana
apple
cherry
banana
aaabnn

aelpp cehrry

</p>