Sphere Online Judge

Computer geeks! Show off your skills and claim the job of your dreams! RecruitCoders.com

SPOJ Problem Set (classical)

27. Sorting Bank Accounts

Problem code: SBANK

In one of the internet banks thousands of operations are being performed every day. Since certain customers do business more actively than others, some of the bank accounts occur many times in the list of operations. Your task is to sort the bank account numbers in ascending order. If an account appears twice or more in the list, write the number of repetitions just after the account number. The format of accounts is as follows: 2 control digits, an 8-digit code of the bank, 16 digits identifying the owner (written in groups of four digits), for example (at the end of each line there is exactly one space):
30 10103538 2222 1233 6160 0142 

Banks are real-time institutions and they need FAST solutions. If you feel you can meet the challenge within a very stringent time limit, go ahead! A well designed sorting algorithm in a fast language is likely to succeed.

Input


t [the number of tests <= 5]
n [the number of accounts<= 100 000]
[list of accounts]
[empty line]
[next test cases]

Output


[sorted list of accounts with the number of repeated accounts]
[empty line]
[other results]

Example

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 

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

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

Added by:Micha³ Ma³afiejski
Date:2004-06-01
Time limit:7s
Source limit:50000B
Languages:All except: PERL 6
Resource:-

hide comments
2012-05-09 19:54:10 stranger
9 tle
2 wa
finally ac 3.97
2012-03-08 21:48:10 Gopal Rander
Someone help.. I am using map.insert and a boolean to check already occured.. gets() for input and cout for ouput.. getting TLE :(

Got AC.. used printf instead of cout..

Last edit: 2012-03-08 22:03:23
2012-03-06 08:33:51 nblt
Used qsort will be TLE?
2012-02-28 23:58:36 CarloSz
AC ~
2012-01-15 09:05:42 HTK
I use radix sort, tested on my computer, finished the largest test case in 0.6s. And I keep getting TLE?? >.<
2011-11-11 13:45:30 pfiesteria
My AC code(5.95s) using gets and printf, The same code if I change printf to cout will got TLE!!! And my AC code(6.00s) in C++ 4.3.2 but got TLE in C++ 4.0 ?

Last edit: 2011-11-13 09:24:09
2011-10-16 10:04:27 Abhishek
wouldn't radix sort work here?
2011-08-26 10:27:09 venkat
I am using maps c++ and gets for taking input but i am getting TLE.
Can we optimise futher?
2011-08-17 22:19:47 Jagat Sastry
Fiddled around a lot with java; Still got TLE.
Got AC with builtin qsort and char** in C.
2011-07-25 11:59:39 manish kapoor
i used map ,but still i'm getting TLE.Smbdy pls tell me the time complexity of my sol...
hw shud i proceed then....

Last edit: 2011-07-25 12:06:53
SPOJ System © 2012 Sphere Research Labs | Projekty informatyczne i aplikacje na zamówienie. All Rights Reserved.