SPOJ SBANK

27 - SBANK - Sorting Bank Account

 * SPOJ SBANK

Summary
Given a list of bank accounts, you need to sort the bank accounts in numberical order, and compact any duplicates as well.

Explanation
The input is a list of bank account numbers in a common format but are unsorted. The output is an enumeration of each account number, followed by the number of times a given account number appears.

The problem is solvable through a direct data structure.

Gotchas

 * Make sure you are using a fast method to compare bank account numbers. For example, comparing strings is slower than comparing integers.

Input
2 6 03 10103538 2222 1233 6160 0142 03 10103538 2222 1233 6160 0141 30 10103538 2222 1233 6160 0141 30 10103538 2222 1233 6160 0142 30 10103538 2222 1233 6160 0141 30 10103538 2222 1233 6160 0142
 * t [the number of tests <= 5]
 * n [the number of accounts<= 100 000]
 * [list of accounts]
 * [empty line]
 * [next test cases]

5 30 10103538 2222 1233 6160 0144 30 10103538 2222 1233 6160 0142 30 10103538 2222 1233 6160 0145 30 10103538 2222 1233 6160 0146 30 10103538 2222 1233 6160 0143

Output
03 10103538 2222 1233 6160 0141 1 03 10103538 2222 1233 6160 0142 1 30 10103538 2222 1233 6160 0141 2 30 10103538 2222 1233 6160 0142 2
 * [sorted list of accounts with the number of repeated accounts]
 * [empty line]
 * [other results]

30 10103538 2222 1233 6160 0142 1 30 10103538 2222 1233 6160 0143 1 30 10103538 2222 1233 6160 0144 1 30 10103538 2222 1233 6160 0145 1 30 10103538 2222 1233 6160 0146 1