Problem:


Rank Checker

時は2020 年。パソコン甲子園 2020 の予選結果を保存したデータがあります。このデータには、各チームに振られる整理番号と正解数が保存されています。ここでは、正解数で順位を決定するものとし、正解数の多いほうから順に 1 位、2 位 ... と順位をつけていくこととします。

予選結果のデータと整理番号をキーボードから入力して、その番号のチームの順位を出力するプログラムを作成してください。

Input

入力データは２つの部分からなります。前半の部分は、予選結果のデータ、後半の部分は順位を知りたいチーム番号の問い合わせです。予選結果のデータの形式は以下の通りです。

p1,s1
p2,s2
...
...
0,0

pi (1 ≤ pi ≤ 100 )、 si (0 ≤ si ≤ 30) はそれぞれ i チーム目の整理番号と正解数を表す整数です。整理番号と正解数がともに 0 のときこのデータの入力が終わるものとします。

続いて後半の問い合わせが複数与えられます。問い合わせの形式は以下の通りです。

q1
q2
:

各問い合わせは１行に整理番号 qi (1 ≤ qi ≤ 30) が与えられます。これを入力の最後まで処理して下さい。問い合わせの数は 100 を超えません。

Output

各問い合わせについて、チームの順位を１行に出力して下さい。

Sample Input

1,20
2,20
3,30
4,10
5,10
6,20
0,0
1
2
4
5

Output for the Sample Input

2
2
3
3

Note

入力例のデータにおいて、チームを正解数順に整列すると：

3,30
1,20
2,20
6,20
4,10
5,10

となります。ここでは、正解数を基に順位を決定するため、30問正解チームを1位、20問正解チームを2位、10問正解チームを3位とします（上位のチーム数を考慮し、10問正解チームを5位とする通常の順位付けとは異なることに注意して下さい）。



Sample input:
1,20
2,20
3,30
4,10
5,10
6,20
0,0
1
2
4
5


Sample output:
2
2
3
3

Submission status: Wrong Answer

Solution code:
team_score=[]
while True:

	x,y=map(int,input().split(','))
	if x==y==0:
		break
	team_score.append((x,y))

team_score.sort(key=lambda x:x[1],reverse=True)
for i,j in team_score:
	print(i)

Submission status: Wrong Answer

Solution code:
def Inquiry(team):
	ranking=1
	score=team_score[0][1]
	for i in team_score:
		if score>i[1]:
			ranking+=1
			score=i[1]
		if i[0]==team:
			return ranking

team_score=[]
while True:

	x,y=map(int,input().split(','))
	if x==y==0:
		break
	team_score.append((x,y))

print(team_score)
team_score.sort(key=lambda x:x[1],reverse=True)
print(team_score)

while True:
	try:
		team=int(input())
		print(Inquiry(team))
	
	except EOFError:
		break

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0061
"""
import sys


def calc_rank(data):
    scores = {}                 #  ?????????key, ???????????????id???????????????value??¨?????????????????????
    for id, point in data:
        if point in scores:
            scores[point].append(id)
        else:
            scores[point] = [id]

    ranks = [k for k in scores.keys()] #  ranks.index(point) ?????????????????????????????????
    ranks.sort(reverse=True)
    ranks.insert(0, 0)          #  index???1?????????????????????????????????????????????????????\
    return scores, ranks



def check_rank(scores, ranks, id):
    for k, v in scores.items():
        if id in v:
            return ranks.index(k)


def main(args):
    data = []

    id, point = [int(x) for x in input().strip().split(',')]
    while id != 0 or point != 0:
        data.append((id, point))
        id, point = [int(x) for x in input().strip().split(',')]
    scores, ranks = calc_rank(data)

    for line in sys.stdin:
        id = int(line.strip())
        result = check_rank(scores, ranks, id)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

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

teams = [0 for i in range(101)]
points = [False for i in range(31)]
while True:
    a,b = [int(i) for i in input().split(",")]
    if a == 0 and b == 0:
        break

    teams[a] = b
    points[b] = True

N = list(get_input())
for l in range(len(N)):
    q = int(N[l])
    p = teams[q]
    ans = 0
    for i in range(30,0,-1):
        if points[i]:
            ans += 1
        if i == p:
            break
    print(ans)

Submission status: Wrong Answer

Solution code:
points = [] ; times = 0
while True:
	x = map(int,raw_input().split(','))
	if x[0]==0 and x[1]==0: break
	else:
		points.append(x[1]) ; times += 1 ; continue
sets = dict(zip(range(times),list(points)))
points.sort(reverse=True)
while True:
	try:
		y = input() - 1
		for val in xrange(times):
			if sets[y] == points[val] : print val+1
	except: break

Submission status: Wrong Answer

Solution code:
a = []
while True:
    p = map(int, raw_input().split(','))
    if p[0] == 0 and p[1] == 0: break
    a.append(p)
a.sort(key=lambda p: p[1], reverse=True)
a[0].append(1)
for i, p in zip(range(1, len(a) + 1), a)[1:]:
    if a[i - 2][1] == p[1]:
        p.append(a[i - 2][-1])
    else:
        p.append(a[i - 2][-1] + 1)
b = {i: [j, n] for i, n, j in a}
print b
try:
    while True:
        p = b[int(raw_input())]
        print p[0]
except EOFError:
    pass

Submission status: Accepted

Solution code:
table = {}
while True:
    p, s = map(int, input().split(","))
    if p == 0:
        break
    table[p] = s
result = {v: i for i, v in enumerate(sorted(set(table.values()), reverse=True), start=1)}

try:
    while True:
        q = int(input())
        print(result[table[q]])
except EOFError:
    pass

Submission status: Accepted

Solution code:
data = {}

while True:
    team, score = input().split(',')
    if team == score == '0': break
    if int(score) in data:
        data[int(score)].append(team)
    else:
        data[int(score)] = [team]

while True:
    try:
        n = input()
    except:
        break
    for d in data.keys():
        if n in data[d]:
            tmp = reversed(list(data.keys()))
            ind = list(tmp).index(d)
            print(ind + 1)

Submission status: Accepted

Solution code:
tp = {}
while 1:
	t,p = map(int,raw_input().split(","))
	if t == p == 0: break
	tp[t] = p
	
plist = sorted([tp[key] for key in tp.keys()],reverse = True)
prank = {}
rank = 1
point = plist[0]
for i in range(len(plist)):
	if plist[i] < point:
		point = plist[i]
		rank += 1
	prank[point] = rank
	
while 1:
	try:
		team = int(raw_input())
	except:
		break
	print prank[tp[team]]

Submission status: Accepted

Solution code:
tp = {}
while 1:
	t,p = map(int,raw_input().split(","))
	if t == p == 0: break
	tp[t] = p
plist = sorted(list(set([tp[key] for key in tp.keys()])),reverse = True)
while 1:
	try:
		team = int(raw_input())
	except:
		break
	print plist.index(tp[team])+1

Submission status: Accepted

Solution code:
tp = {}
while 1:
	t,p = map(int,raw_input().split(","))
	if t==p==0:break
	tp[t]=p
ls=sorted(list(set([tp[key] for key in tp.keys()])),reverse=True)
while 1:
	try:team=int(raw_input())
	except:break
	print ls.index(tp[team])+1

Submission status: Accepted

Solution code:
import sys
d={}
while 1:
  a,b=map(int,raw_input().split(","))
  if a==b==0: break
  d[a]=b

x=sorted(set(d.values()))[::-1]
for s in sys.stdin:
  print x.index(d[int(s)])+1

Submission status: Accepted

Solution code:
from bisect import bisect
import sys

d = {}
p = []
for s in sys.stdin:
    t,n = map(int,s.split(","))
    if [t,n] == [0,0]: break
    d[t] = n
    p.append(n)

p = sorted(list(set(p)))
for s in sys.stdin:
    print len(p)+1 -bisect(p, d[int(s)])

Submission status: Accepted

Solution code:
import sys
f = sys.stdin

teams = {}
scores = set()
while True:
    team, score = map(int, f.readline().split(','))
    if team == score == 0:
        break
    teams[team] = score
    scores.update([score])
scores = sorted(list(scores))[::-1]
for line in f:
    print(scores.index(teams[int(line)]) + 1)

Submission status: Accepted

Solution code:
l = []
s = set()
while True:
	n, a = input()
	if n == a == 0:
		break;
	l.append(a)
	s.add(a)

s = list(s)
s.reverse()
while True:
	try:
	    n = input()
	except:
		break
	print(s.index(l[n-1])+1)

Submission status: Accepted

Solution code:
result = {}
while True:
    num, accepted = map(int, raw_input().split(','))
    if num == 0 and accepted == 0: 
        break
    else:
        result[num] = accepted

rank = 1
accepted = 0      
for k, v in sorted(result.items(), key=lambda x: x[1], reverse=True):
    if accepted > v:
        rank += 1
    result[k] = rank
    accepted = v
        
while True:
    try:
        num = int(raw_input())
        print result[num]
    except EOFError:
        break

Submission status: Accepted

Solution code:
list = []
dict = {}

while True:
	team,point = map(int,raw_input().split(","))
	if team == 0 and point == 0:
		break
	
	dict[team] = point
	if not point in list:
		list.append(point)
	
list.sort()
list.reverse()

while True:
	try:
		team = int(raw_input())
	except EOFError:
		break
	
	print list.index(dict[team]) + 1

Submission status: Accepted

Solution code:
import sys
d1 = {}
l = []
while True:
  a,b = input().split(',')
  if (a,b) == ('0','0'):
    break
  else:
    d1[a] = int(b)
    if (int(b) not in l):
      l.append(int(b))
l.sort()
l.reverse()
for line in sys.stdin.readlines():
  n = line.replace('\n','')
  print(l.index(d1[n])+1)

Submission status: Accepted

Solution code:
l=set()
s={}
while 1:
    n,k=map(int,raw_input().split(','))
    if n==k==0:
        break
    l.add(k)
    s[n]=k
l2=sorted(list(l))[::-1]
while 1:
    try:
        n=int(raw_input())
        print l2.index(s[n])+1
    except:
        break

Submission status: Accepted

Solution code:
def Inquiry(team):
	ranking=1
	score=team_score[0][1]
	for i in team_score:
		if score>i[1]:
			ranking+=1
			score=i[1]
		if i[0]==team:
			return ranking

team_score=[]
while True:

	x,y=map(int,input().split(','))
	if x==y==0:
		break
	team_score.append((x,y))

#print(team_score)
team_score.sort(key=lambda x:x[1],reverse=True)
#print(team_score)

while True:
	try:
		team=int(input())
		print(Inquiry(team))
	
	except EOFError:
		break

Submission status: Accepted

Solution code:
#encoding=utf-8
import sys
data1, data2 = [], []


while True:
    x = map(int, raw_input().split(","))
    if sum(x) == 0:
        break
    data1.append([x[1], x[0]])

i = 1
data1 = sorted(data1)[::-1]
data1[0].insert(2,1)
ma = data1[0][0]

while True:
    if ma == data1[i][0]:
        data1[i].insert(2, (data1[i - 1][2]))
    elif ma > data1[i][0]:
        data1[i].insert(2,((data1[i - 1][2]) + 1))
        ma = data1[i][0]
    i += 1
    if i >= len(data1):
        break


for i in sys.stdin:
    for j in xrange(len(data1)):
        if int(i) == data1[j][1]:
            print data1[j][2]
            break

Submission status: Accepted

Solution code:
arr = {}
rankScore = []
while True:
    s = list(map(int, input().split(',')))
    if s[0] == 0:
        break
    arr[s[0]] = s[1]
    if s[1] not in rankScore:
        rankScore.append(s[1])
rankScore.sort(reverse = True)
while True:
    try:
        num = int(input())
        print(rankScore.index(arr[num])+1)
    except:
        break

Submission status: Accepted

Solution code:
ps, ses = [], []
while True:
    p, s = map(int, input().split(','))
    if not p:
        break
    ps.append(p)
    ses.append(s)
rank = []
for s in ses:
    if s not in rank:
        rank.append(s)
rank.sort(reverse=True)
while True:
    try:
        q = int(input())
    except:
        break
    print(rank.index(ses[ps.index(q)]) + 1)

Submission status: Accepted

Solution code:
import itertools
from operator import itemgetter
nums={}

while True:
    p,s=map(int,input().split(','))
    if(p==0 and s==0):break
    if not s in nums:
        nums[s]=[]
    nums[s].append(p)

while True:
    try:
        q=int(input())
        ans=len(nums)
        for ns in nums.items():
            if q in ns[1]:
                print(ans)
                break
            ans-=1

            

    except:
        break

Submission status: Accepted

Solution code:
nums={}
while True:
    p,s=map(int,input().split(','))
    if(p==0 and s==0):break
    if not s in nums:
        nums[s]=[]
    nums[s].append(p)

while True:
    try:
        q=int(input())
        ans=len(nums)
        for ns in nums.items():
            if q in ns[1]:
                print(ans)
                break
            ans-=1
    except:
        break

Submission status: Accepted

Solution code:
Poi = []
Tea = []
while True:
    
    p,s = map(int,input().split(","))
    if p == 0 and s == 0:
        break
    Poi.append(s)
    Tea.append(p)
Poi_ran = sorted(sorted(set(Poi), key=Poi.index))
while True:
    try:
        q = int(input())
        point = Poi[Tea.index(q)]
        print(len(Poi_ran) - Poi_ran.index(point))
    except EOFError:
        break

Submission status: Accepted

Solution code:
import sys
import fileinput
import math

ips = []
for line in fileinput.input():
    ips.append(line)

data = []
i = 0
while True:
    ip = [ int(i) for i in ips[i].strip().split(',')]
    if ip == [0,0] : break;
    else: data.append(ip)
    i+=1

data = sorted(data,key=lambda x:-x[1])
counter = 0
score = -1

m = {}
for k, s in data:
    if s != score:
        counter+=1
        score = s
    m[k] = counter

for a in range(i+1, len(ips)):
    ip = int(ips[a].strip())
    print(m[ip])

Submission status: Accepted

Solution code:
ps=[]
while True:
    p, s= map(int, input().split(","))
    if p==s==0: break
    ps.append((p, s))
o= sorted(set(s for p, s in ps), reverse=True)
zo= dict(zip(o, [i+1 for i in range(len(o))]))
while True:
    try:
        q= int(input())
        for p, s in ps:
            if p== q: print(zo[s])
    except:
        break

Submission status: Accepted

Solution code:
p = []
while True:
    s = input()
    if s == "0,0":
        break
    p.append([int(i) for i in s.split(",")])

p.sort(key = lambda x : x[1], reverse = True)

while True:
    try:
        n = int(input())
    except:
        break
    ans = 1
    for i in range(len(p)):
        if i != 0 and p[i][1] != p[i - 1][1]:
            ans += 1
        if p[i][0] == n:
            print(ans)
            break

Submission status: Accepted

Solution code:
c=[]
d={}
while 1:
    a,b=map(int,input().split(','))
    if a==0:break
    c+=[b]
    d[a]=b
c=sorted(set(c))[::-1]
while 1:
    try:print(c.index(d[int(input())])+1)
    except:break

Submission status: Accepted

Solution code:
po = []
t2p = {}
while True:
    t, p = list(map(int, input().strip().split(',')))
    if t==0 and p==0:
        break
    t2p[t] = p
    po.append(p)

ps = sorted(list(set(po)),reverse=True)
while True:
    try:
        q = int(input().strip())
        r = 1
        for i in ps:
            if t2p[q] < i:
                r += 1
            else:
                break
        print(r)

    except EOFError:
        break

Submission status: Accepted

Solution code:
A = {}
while True:
    p,s = map(int,input().split(','))
    if p == 0:
        break
    A [p] = s

while True:
    try:
        q = int(input())
    except EOFError:
        break
    st = {A [i] for i in A.keys() if i != q and A [i] > A [q]}
    print(len(st) + 1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import os

scores = [0]

for s in sys.stdin:
    p, s = map(int, s.split(','))
    if p == s == 0:
        break
    else:
        scores.append(s)

score_set = set(scores)
score_set = list(score_set)
score_set.sort(reverse=True)

for s in sys.stdin:
    n = int(s)

    teams_score = scores[n]
    print(score_set.index(teams_score) + 1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0061
"""
import sys


def calc_rank(data):
    scores = {}                 #  ?????????key, ???????????????id???????????????value??¨?????????????????????
    for id, point in data:
        if point in scores:
            scores[point].append(id)
        else:
            scores[point] = [id]

    ranks = [k for k in scores.keys()] #  ranks.index(point) ???????????????????????????????????????????????????
    ranks.sort(reverse=True)
    ranks.insert(0, -1)          #  index???1?????????????????????????????????????????????????????\
    return scores, ranks


def check_rank(scores, ranks, id):
    for k, v in scores.items():
        if id in v:
            return ranks.index(k)


def main(args):
    data = []
    id, point = [int(x) for x in input().strip().split(',')]
    while id != 0 or point != 0:
        data.append((id, point))
        id, point = [int(x) for x in input().strip().split(',')]
    scores, ranks = calc_rank(data)

    for line in sys.stdin:
        id = int(line.strip())
        result = check_rank(scores, ranks, id)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
# Aizu Problem 0061: Rank Checker
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


points = {}    
while True:
    no, p = [int(_) for _ in input().split(',')]
    if no == p == 0:
        break
    if p not in points:
        points[p] = []
    points[p].append(no)
rank = sorted(list(points.keys()), reverse=True)

while True:
    try:
        team = int(input())
    except EOFError:
        break
    for i in range(len(rank)):
        if team in points[rank[i]]:
            print(i + 1)
            break

Submission status: Accepted

Solution code:
score = [[] for i in range(31)]
while True:
    try:
        p, s = map(int, input().split(","))
        if p == 0:
            break
        score[s].append(p)
    except:
        break

rank = {}
j = 1
for i in range(31)[::-1]:
    if len(score[i]) > 0:
        rank[i] = j
        j += 1

while True:
    try:
        p = int(input())
        for i in range(31):
            if p in score[i]:
                print(rank[i])
    except:
        break

Submission status: Accepted

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

teams = [0 for i in range(101)]
points = [False for i in range(31)]
while True:
    a,b = [int(i) for i in input().split(",")]
    if a == 0 and b == 0:
        break

    teams[a] = b
    points[b] = True

N = list(get_input())
for l in range(len(N)):
    q = int(N[l])
    p = teams[q]
    ans = 0
    for i in range(30,-1,-1):
        if points[i]:
            ans += 1
        if i == p:
            break
    print(ans)

Submission status: Accepted

Solution code:
import sys
d,e={},{}
for x in iter(input,'0,0'):
 p,s=map(int,x.split(','))
 d.setdefault(s,[]);d[s]+=[p]
 e[p]=s
for y in sys.stdin:print(sorted(d.keys())[::-1].index(e[int(y)])+1)

Submission status: Accepted

Solution code:
import sys
c,d=[],{}
for x in iter(input,'0,0'):
 p,s=map(int,x.split(','))
 c+=[s]
 d[p]=s
for y in sys.stdin:print(sorted({*c})[::-1].index(d[int(y)])+1)

Submission status: Accepted

Solution code:
import sys
c,d=[],{}
for x in iter(input,'0,0'):p,s=map(int,x.split(','));c+=[s];d[p]=s
for y in sys.stdin:print(sorted({*c})[::-1].index(d[int(y)])+1)

Submission status: Accepted

Solution code:
lst = []

while True:
  p, s = map(int, input().split(","))
  if not p:
    break

  lst.append((s, p))

lst.sort(reverse=True)

dic = {}

rank = 0
solve_num = 0
for t in lst:
  if solve_num == t[0]:
    dic[t[1]] = rank
  else:
    rank += 1
    solve_num = t[0]
    dic[t[1]] = rank

while True:
  try:
    print(dic[int(input())])
  except EOFError:
    break

Submission status: Accepted

Solution code:
import sys
from collections import Counter
p=[tuple(map(int,l.split(","))) for l in sys.stdin]
d=[i for i in p if len(i)==2][:-1]

rank=sorted(Counter([i[1] for i in d]).keys(),reverse=True)
m=sorted(d,key=lambda x:x[1],reverse=True)
tix=[i[0] for i in p if len(i)==1]
[print(rank.index(k[1])+1) for k in [i for i in m for j in tix if i[0]==j]]

Submission status: Accepted

Solution code:
# AOJ 0061 Rank Checker
# Python3 2018.6.15 bal4u

team = {}
while True:
	p, s = list(map(int, input().split(',')))
	if p == 0: break
	team[p] = s
tbl = sorted(team.items(), key=lambda x:x[1], reverse=True)

ans = [0]*101
ans[tbl[0][0]] = ord = 1
for i in range(1,len(tbl)):
	if tbl[i][1] < tbl[i-1][1]: ord += 1
	ans[tbl[i][0]]= ord
	
while True:
    try:
        print(ans[int(input())])
    except EOFError:
        break

Submission status: Accepted

Solution code:
import sys
li=[0]*101
sc=[False]*31
ra=[0]*31
while True:
    (n,s)=map(int,raw_input().split(","))
    if (n,s)==(0,0):break
    sc[s]=True
    li[n]=s
r=1
for i in xrange(30,-1,-1):
    if sc[i]:
        ra[i]=r
        r+=1
for line in sys.stdin.readlines():
    print ra[li[int(line.strip())]]

Submission status: Accepted

Solution code:

import sys
import itertools


class Team:
    def __init__(self, number, score):
        self.number = number
        self.score = score


class RankChecker:
    def __init__(self):
        self.teams = []

    def add(self, team):
        self.teams.append(team)

    def aggregate(self):
        self.teams.sort(key=lambda t: t.score, reverse=True)
        r = 0
        for k, g in itertools.groupby(self.teams, key=lambda t: t.score):
            r += 1
            for t in g:
                t.rank = r

    def check_rank(self, team_number):
        team = filter(lambda t: t.number == team_number, self.teams)[0]
        return team.rank



rc = RankChecker()
for line in sys.stdin:
    num, score = map(int, line.strip().split(','))
    if (num, score) == (0, 0):
        break
    rc.add(Team(num, score))
rc.aggregate()
for line in sys.stdin:
    num = int(line)
    print rc.check_rank(num)

Submission status: Accepted

Solution code:
team = [0 for i in range(101)]
point= [[0 for i in range(2)] for i in range(31)]
while 1:
    temp= map(int, raw_input().split(','))
    if temp[0] ==0==temp[1]:
        break
    team[temp[0]]=temp[1]
    if point[temp[1]][1]==0:
        point[temp[1]][1]=1
        for i in range(temp[1]+1):
            point[i][0]+=1
while 1:
    try:
        n = input()
        print point[team[n]][0]
    except EOFError:
	break

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

L = []
while True:
    line = stdin.readline()
    if line.startswith('0,0'):
        break
    L.append(tuple(int(s) for s in line.split(',')))

L.sort(key=lambda (id, point): point, reverse=True)
for line in stdin:
    n = int(line)
    order = 0
    p = 0
    for id, point in L:
        if p != point:
            p = point
            order += 1
        if n == id:
            break
    print(order)

Submission status: Accepted

Solution code:
t = []
while 1:
    n,a = map(int, raw_input().split(','))
    if n==a==0: break
    t.append([a,n])
t.sort(reverse = True)
o = [0]*(len(t)+1); c = 1;
o[t[0][1]] = 1;
for i in xrange(1,len(t)):
    if t[i-1][0]!=t[i][0]:
        c += 1
    o[t[i][1]] = c
while 1:
    try:
        n = input()
        print o[n]
    except EOFError:
        break

Submission status: Accepted

Solution code:
import sys
d={}
f=0
for s in sys.stdin:
    if f==0:
        a,b=map(int,s.split(","))
        if a==0 and b==0:
            x=sorted(set(d.values()))[::-1]
            f=1
        else:d[a]=b
    else:
        print x.index(d[int(s)])+1

Submission status: Accepted

Solution code:
import sys
d={}
f=0
for s in sys.stdin:
    if f==0:
        a,b=map(int,s.split(","))
        if a!=0 or b!=0:d[a]=b
        else:
            x=sorted(set(d.values()))[::-1]
            f=1
    else:print x.index(d[int(s)])+1

Submission status: Accepted

Solution code:
flag = 1
data = []
query = []
while True:
    try:
        while flag:
            n,s = map(int, raw_input().split(","))
            if n == 0 and s == 0:
                flag = 0
                break
            data.append([s,n])
        query.append(int(raw_input()))
    except:
        break
    
data.sort(); data.reverse()

rank = 0
rslt = {}
mx = 31
for i in data:
    if i[0] < mx:
        rank += 1
        mx = i[0]
    rslt[i[1]] = rank

for i in query:
    print rslt[i]

Submission status: Accepted

Solution code:
teams = dict()
while 1:
    a, b = map(int, raw_input().split(','))
    if a == b == 0:
        break
    teams[a] = b
cur = 1 << 30
cur_rank = 0
ret = dict()
for k, v in sorted(teams.items(), key=lambda a: a[1], reverse=True):
    if v < cur:
        cur_rank += 1
        cur = v
    ret[k] = cur_rank

while 1:
    try:
        query = input()
        print ret[query]
    except EOFError:
        break

Submission status: Accepted

Solution code:
lst = []

while True:
    p, s = map(int, input().split(','))

    if p == 0 :
        break

    lst.append(s)

s = list(set(lst))
s.sort(reverse = True)

while True:
    try:
        num = int(input())
        print(s.index(lst[num-1]) +1)

    except EOFError:
        break

Submission status: Accepted

Solution code:
List = [0] * 101
while True :
    p, s = map(int, input().split(","))
    if p == 0 and s == 0 :
        break
    
    List[p] = s

Sorted_List = sorted(list(set(List)), reverse = True)

while True :
    try :
        q = int(input())
    except EOFError :
        break
    
    print(Sorted_List.index(List[q])+1)

Submission status: Accepted

Solution code:

c = []
d = {}
while True:
    a,b = map(int, input().split(','))
    c += [b]
    d[a] = b
    if a == 0 : break
c = sorted(set(c))[::-1]
while True:
    try:print(c.index(d[int(input())])+1)
    except: break

Submission status: Accepted

Solution code:
datas = []

while True:
    n,s = (int(x) for x in input().split(","))
    if n == 0:
        break;
    datas.append((n,s))
datas = sorted(datas,key = lambda x:x[1],reverse=True)

while True:
    try:
        q = int(input())
        rank = 1
        score = datas[0][1]
    
        for n,s in datas:
            if score > s:
                score = s
                rank += 1
            if n == q:
                break
        print(rank)
    except:
        break

Submission status: Accepted

Solution code:
#正解数で順位を決定
team=[]
point=[]
dic={}
while True:
    p,s=map(int, input().split(","))
    if p==s==0:
        break
    team.append([p,s])
    if s not in point:
        point.append(s)
        
point.sort(reverse=True)

#辞書(得点,順位)で作る
for i in range(len(point)):
    dic[point[i]]=i+1
    
while True:
    try:
        n=int(input())
    except EOFError:
        break
    print(dic[team[n-1][1]])

Submission status: Accepted

Solution code:
P = [-1] * 101
while True:
    t, p = [int(x) for x in input().split(",")]
    if t == 0 and p == 0:
        break
    P[t] = p

L = sorted(set(P),reverse=True)
#print(L)
d = dict()
for rank, point in enumerate(L,start=1):
    d[point] = rank
#print(d)
while True:
    try:
        t = int(input())
    except:
        break

    p = P[t]
    print(d[p])

Submission status: Accepted

Solution code:
t = [0] * 101
while 1:
    p, s = map(int, input().split(','))
    if p == s == 0:
        break
    t[p] = s

rank = list(set(t))
rank.sort(reverse=True)

while 1:
    try:
        n = int(input())
        print(rank.index(t[n])+1)
    except:
        break

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    
    ans = []
    ans2 = []
    
    while True:
        n,m = map(int,input().split(","))
        
        if n == 0 and m == 0:
            break
        
        if m not in ans:
            ans.append(m)
        ans2.append((n,m))
        
        ans.sort()
        ans.reverse()
        
    while True:
        try:
            x = int(input())
            y = ans2[x-1][1]
            ind = ans.index(y) + 1

            print(ind)
        except EOFError:
            break

Submission status: Accepted

Solution code:
def answer():
    point={}
    number=[]
    number_n=[]
    while 1:
        N=list(map(int,input().split(",")))
        if N==[0,0]:break
        number.append(N)
        number_n.append(N[1])
    number_n=sorted(number_n)[::-1]
    count=1
    co=number_n[0]
    for i in number_n:
        if i in point:continue
        elif i<co:
            count +=1
            co=i
            point[co]=count
        else:point[i]=count
    data={}
    for j in number:
        if j[1] in point:data[j[0]]=point[j[1]]
    return data

ans=answer()
while 1:
    try:print(ans[int(input())])
    except:break

Submission status: Accepted

Solution code:
team=[0]*101
while 1:
    p,s=map(int,input().split(","))
    if p==s==0:break
    team[p]=s
rank=list(set(team))
rank.sort(reverse=True)
while 1:
    try:
        n=int(input())
        print(rank.index(team[n])+1)
    except:break

Submission status: Accepted

Solution code:
p = []
q = []
while(1):
    a,b = [int(i) for i in input().split(",")]
    if a == 0 and b == 0:
        break
    p.append(a)
    q.append(b)
q_ = sorted(list(set(q)))
q_rank = [i+1 for i in range(len(q_))[::-1]]
q_dic = dict(zip(q_,q_rank))
rank = dict(zip(p,[q_dic[i] for i in q]))

while(1):
    try:
        a = int(input())
        print(rank[a])
    except EOFError:
        break

Submission status: Accepted

Solution code:
scorelist = []

while 1:
    num, score = map(int, input().split(","))
    if num == 0 and score == 0:
        break

    scorelist.append(score)

score_unique = list(set(scorelist))
score_unique.sort(reverse=True)

while 1:
    try:
        q = int(input())
    except:
        break

    score = scorelist[q-1]

    for i, s in enumerate(score_unique):
        if score == s:
            print(i + 1)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

import sys

class Team_class():
    def __init__(self, id, score):
        self.id = id
        self.score = score
        self.rank = 0

team = []
for line in sys.stdin:
    id, s = map(int, line.split(','))
    if id + s == 0:
        break
    team.append(Team_class(id, s))
for i in range(len(team)):
    for j in range(i, len(team)):
        if team[i].score < team[j].score:
            team[i], team[j] = team[j], team[i]
tmpscore = team[0].score
tmprank = 1
for i in range(len(team)):
    if tmpscore != team[i].score:
        tmpscore = team[i].score
        tmprank += 1
    team[i].rank = tmprank
for line in sys.stdin:
    print team[int(line)].rank

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

import sys

class Team_class():
    def __init__(self, id, score):
        self.id = id
        self.score = score
        self.rank = 0

team = []
while True:
    id, s = map(int, raw_input().split(','))
    if id + s == 0:
        break
    team.append(Team_class(id, s))
for i in range(len(team)):
    for j in range(i, len(team)):
        if team[i].score < team[j].score:
            team[i], team[j] = team[j], team[i]
tmpscore = team[0].score
tmprank = 1
for i in range(len(team)):
    if tmpscore != team[i].score:
        tmpscore = team[i].score
        tmprank += 1
    team[i].rank = tmprank
for line in sys.stdin:
    print team[int(line)].rank

Submission status: Runtime Error

Solution code:
import sys
c,d=[],{}
for x in iter(input,'0,0'):p,s=map(int,x.split(','));c+=[s];d[p]=s
for y in sys.stdin:print({*c}.sort()[::-1].index(d[int(y)])+1)

Submission status: Runtime Error

Solution code:


team = [0 for i in range(101)]
point= [[0 for i in range(2)] for i in range(31)]
while 1:
    temp= map(int, raw_input().split(','))
    if temp[0] ==0==temp[1]:
        break
    team[temp[0]]=temp[1]
    if point[temp[1]][1]==0:
        point[temp[1]][1]=1
        for i in range(temp[1]+1):
            point[i][0]+=1
while 1:
    n = input()
    print point[team[n]][0]

Submission status: Runtime Error

Solution code:
team = [0 for i in range(101)]
point= [[0 for i in range(2)] for i in range(31)]
while 1:
    temp= map(int, raw_input().split(','))
    if temp[0] ==0==temp[1]:
        break
    team[temp[0]]=temp[1]
    if point[temp[1]][1]==0:
        point[temp[1]][1]=1
        for i in range(temp[1]+1):
            point[i][0]+=1
while 1:
    try:
        n = input()
        print point[team[n]][0]
    except EOFerror:
	break