Problem:


Book Index

Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers.

You can assume that a word consists of at most 30 characters, and the page number is less than or equal to 1000. The number of pairs of a word and a page number is less than or equal to 100. A word never appear in a page more than once.

The words should be printed in alphabetical order and the page numbers should be printed in ascending order.

Input

word page_number
    :
    :

Output

word
a_list_of_the_page_number
word
a_list_of_the_Page_number
      :
      :

Sample Input

style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18

Output for the Sample Input

document
13
easy
9
even
18 25
introduction
3
style
7 12 21



Sample input:
style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18


Sample output:
document
13
easy
9
even
18 25
introduction
3
style
7 12 21

Submission status: Accepted

Solution code:
index={}
while True:
    try:
        word,page=input().split(" ")
        page=int(page)
        tmp=index.get(word,[])
        tmp.append(page)
        index[word]=tmp

    except EOFError:
        break


index=sorted(index.items())
for object in index:
    print(object[0])
    print(" ".join([str(i) for i in sorted(object[1])]))

Submission status: Accepted

Solution code:
key_list=[]
page_list=[]
while 1:
    try:
        key,page=map(str,input().split())
        if key in key_list:
            page_list[key_list.index(key)].append(int(page))
        else:
            key_list.append(key)
            page_list.append([int(page)])
    except:break
key_list_sort=key_list[:]
key_list_sort.sort()
for i in key_list_sort:
    print(i)
    ans=page_list[key_list.index(i)][:]
    ans.sort()
    print(' '.join(map(str,ans)))

Submission status: Accepted

Solution code:
dic = {}
while 1:
    try:
        word, page = map(str, input().split())
        page = int(page)
        if word in dic:
            dic[word].append(page)
        else:
            dic[word] = [page]
    except:
        break

for d in sorted(dic):
    print(d)
    print(' '.join(map(str, sorted(dic[d]))))

Submission status: Accepted

Solution code:
d = {}
while True:
    try:
        w, p = input().split()
        if w in d:
            d[w].append(int(p))
        else:
            d[w] = [int(p)]
    except:
        break
for k in sorted(d.items(), key=lambda x: x[0]):
    print(k[0])
    print(*sorted(k[1]))

Submission status: Accepted

Solution code:
result = {}
while True:
    try: n = input()
    except: break
    word, number = n.split()
    if word in result:
        result[word].append(number)
    else:
        result[word] = [number]
    
for k, v in sorted(result.items()):
    val = sorted(list(map(int, v)))
    print(k + '\n' + ' '.join(map(str, val)))

Submission status: Accepted

Solution code:
book = {}
while True:
    a = b = 0
    try:
        a, b = input().split()
        b = int(b)
        if a in book:
            book[a].append(b)
        else:
            book[a] = [b]
    except:
        break
for i, m in sorted(book.items(), key = lambda x: x[0]):
    print(i)
    print(" ".join(str(j) for j in sorted(m)))

Submission status: Accepted

Solution code:
book = {}
while True:
    try:
        w, n = input().split()
        w = str(w).lower()
        n = int(n)
        if (w not in book.keys()):
            book[w] = [n]
        else:
            book[w] += [n]
    
    except EOFError:
        break
    
W = []
for w, nlist in book.items():
    nlist.sort()
    W.append(w)
W.sort()
for w in W:
    print(w)
    print(*book[w])

Submission status: Accepted

Solution code:
dic = {}
while(True):
    try:
        key, page = input().split()
        page = int(page)
    except:
        break
    try:
        dic[key].append(page)
    except:
        dic[key] = [page]
a = list(dic.keys())
a.sort()
for b in a:
    print(b)
    print(" ".join(str(e) for e in sorted(dic[b])))

Submission status: Runtime Error

Solution code:
d={}
for s in sys.stdin:
  w,p=s.split()
  if not w in d: d[w]=[]
  d[w].append(int(p))
for w in sorted(d.keys()):
  print w,"\n"," ".join(map(str,sorted(d[w])))

Submission status: Runtime Error

Solution code:
d={}
for s in sys.stdin:
  w,p=s.split()
  if not w in d: d[w]=[]
  d[w].append(int(p))
for w in sorted(d.keys()):
  print w,"\n"
  print " ".join(map(str,sorted(d[w])))

Submission status: Runtime Error

Solution code:
d={}
for s in sys.stdin:
  w,p=s.split()
  if w in d: d[w].append(int(p))
  else: d[w]=int(p)
  
for w in sorted(d.keys()):
  print w,"\n"
  print " ".join(map(str,sorted(d[w])))

Submission status: Runtime Error

Solution code:
book_index = {}
    while True:
        try:
            word, page = input().split(' ')
            page = int(page)
            page_list = book_index.get(word)
            if page_list:
                page_list.append(page)
            else:
                book_index[word] = [page]
        except Exception:
            break

    for k in sorted(book_index.keys()):
        print(k)
        print(' '.join(map(str, (sorted(book_index.get(k))))))

Submission status: Runtime Error

Solution code:
dic = {}
while True:
    try:
        word, pgn = input().split()
    except ValueError:
        break

    if word in dic.keys():
        dic[word].append(int(pgn))
    else:
        dic[word] = [int(pgn)]
for k, v in dic.items():
    print(k)
    print(' '.join(map(str, sorted(v))))

Submission status: Runtime Error

Solution code:
dic = {}
while True:
    try:
        word, pgn = input().split()

    if word in dic.keys():
        dic[word].append(int(pgn))
    else:
        dic[word] = [int(pgn)]
    except:
        for k, v in dic.items():
            print(k)
            print(' '.join(map(str, sorted(v))))
        break

Submission status: Runtime Error

Solution code:
dic = {}
while True:
    try:
        word, pgn = input().split()

    if word in dic.keys():
        dic[word].append(int(pgn))
    else:
        dic[word] = [int(pgn)]
    except:
        break
        
for k, v in dic.items():
    print(k)
    print(' '.join(map(str, sorted(v))))

Submission status: Runtime Error

Solution code:
import sys
a={}
for i in sys.stdin:
	b,c=i.split()
	a.setdefault(b, []).append(c)
	if c=='18':break
for a,b in sorted(a.items(), key=lambda x: x[0]):
    print(a)
    print(*b.sort())

Submission status: Runtime Error

Solution code:
import sys

dic = {}
while True:
	try:
		a,b = map(str,input(),split())
		page = int(b)

		if a not in dic:
			dic[a] = [page]
		else:
			dic[a].append(page)
			
	except EOFError:
		sorted(dic.keys())
		names = list(dic.keys())
		for i in range(len(names)):
			print(names[i])
			for j in range(len(dic[i])):
				if j == len(dic[i])-1:
					print(dic[i][j])
				else:
					sys.stdout.write(dic[i][j])
		break

Submission status: Runtime Error

Solution code:
index = {}
while True:
    try:
        w, p = map(str, raw_input().split())
        index.setdefault(w,[]).append(int(p))
index.sort()
for i in index:
    index[i].sort()
    print i
    print " ".join(map(int, index[i]))

Submission status: WA: Presentation Error

Solution code:
dict = {}

while True:
	try:
		a,b = map(str,raw_input().split())
	except EOFError:
		break
	
	if a in dict:
		dict[a].append(int(b))
	else:
		dict[a] = [int(b)]
	
for var in dict:
	dict[var].sort()

dic = list(dict.keys())
dic.sort()

for var in dic:
	print var
	for i in xrange(len(dict[var])):
		print dict[var][i],
	print ""

Submission status: WA: Presentation Error

Solution code:
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

N = list(get_input())
N.sort()

N1,N2 = N[0].split()
word = N1
pnum = []
pnum.append(int(N2))

for l in range(1, len(N)):
    N1,N2 = N[l].split()

    if word != N1:
        print(word)
        pnum.sort()
        print(pnum[0], end="")
        for i in range(1, len(pnum)):
            print(" ", end="")
            print(pnum[i], end="")
        print("")
        word = N1
        pnum.clear()
        pnum.append(int(N2))
    else:
        pnum.append(int(N2))

print(word)
pnum.sort()
print(pnum[0], end="")
for i in range(1, len(pnum)):
    print(" ", end="")
    print(pnum[i], end="")

Submission status: WA: Presentation Error

Solution code:
import sys
ans = {}
while True:
  try:
    t = raw_input().split()
    if t[0] not in ans.keys():
      ans[t[0]] = [int(t[1])]
    else:
      hoge = ans.keys().index(t[0])
      ans.values()[hoge].append(int(t[1]))
  except EOFError: 
    break
for k,v in sorted(ans.items()):
  print k
  for i in sorted(v):
    sys.stdout.write("%d "%i)
  else: print