Problem:


取引

取引先の顧客番号と取引日を月ごとに記録したデータがあります。今月のデータと先月のデータを読み込んで、先月から２ヶ月連続で取引のある会社の顧客番号と取引のあった回数を出力するプログラムを作成してください。ただし、月々の取引先数は 1,000 社以内です。

Input

今月のデータと、先月のデータが１行の空行で区切られて与えられます。それぞれのデータは以下のような形式で与えられます。

c1,d1
c2,d2
...
...

ci (1 ≤ ci ≤ 1,000) は顧客番号を表す整数、 di (1 ≤ di ≤ 31) は取引日を表す整数です。

Output

２ヶ月連続で取引のある会社について、顧客番号が小さい順に顧客番号と取引回数の総数を空白で区切って出力します。

Sample Input

123,10
56,12
34,14

123,3
56,4
123,5

Output for the Sample Input

56 2
123 3



Sample input:
123,10
56,12
34,14

123,3
56,4
123,5


Sample output:
56 2
123 3

Submission status: Accepted

Solution code:
from collections import Counter

current = last_month = Counter()
this_month = Counter()

while True:
    try:
        s = input()
    except EOFError:
        break
    if s:
        customer, day = map(int, s.split(','))
        current[customer] += 1
    else:
        current = this_month

for i in last_month.keys():
    if i in this_month:
        print(i, last_month[i] + this_month[i])

Submission status: Accepted

Solution code:
clst1 = [0]*1001
clst2 = [0]*1001

while True:
    inp = input()
    if inp == '':
        break

    lst = list(map(int, inp.split(',')))
    clst1[lst[0]] +=1

while True:
    try:
        lst = list(map(int,input().split(',')))
        clst2[lst[0]] +=1

    except EOFError:
        break

for i in range(1001):
    if clst1[i]*clst2[i] :
        print(str(i) + ' ' + str(clst1[i]+clst2[i]))

Submission status: Accepted

Solution code:
dic = dict()
while 1:
    try:
        c,d = (int(x) for x in input().split(","))
    except:
        break
    value = dic.get(c)
    if not value:
        dic.setdefault(c,-1)
    else:
        dic.update({c:value - 1})

while 1:
    try:
        c,d = (int(x) for x in input().split(","))
    except:
        break
    value = dic.get(c)
    if value:
        if value < 0:
            value *= -1
        dic.update({c:value + 1})
dic = dict(sorted(dic.items()))

for x, y in dic.items():
    if y > 0:
        print(x,y)

Submission status: Accepted

Solution code:
lastMonth={}
thisMonth={}

month="last"

while True:
    try:
        s=input()
        if s=="":
            month="this"
            continue
        c,d=[int(i) for i in s.split(",")]
        if month=="last":
            lastMonth[c]=lastMonth.get(c,0)+1
        else:
            thisMonth[c]=thisMonth.get(d,0)+1
    except EOFError:
        break


for key in sorted(list(set(thisMonth.keys()) & set(lastMonth.keys()))):
    print(key,thisMonth[key]+lastMonth[key])

Submission status: Accepted

Solution code:
from collections import defaultdict

da = defaultdict(int)
while True:
    s = input()
    if len(s) == 0:
        break
    c, n = [int(x) for x in s.split(",")]
    da[c] += 1

db = defaultdict(int)
while True:
    try:
        s = input()
    except:
        break
    c, n = [int(x) for x in s.split(",")]
    db[c] += 1


sa = set([k for k in da.keys() if da[k] > 0])
sb = set([k for k in db.keys() if db[k] > 0])

for c in sorted(sa&sb):
    print(c,da[c]+db[c])

Submission status: Accepted

Solution code:
C1 = list()
D1 = list()

while True :
    try :
        c, d = map(int, input().split(","))
        C1.append(c)
        D1.append(d)
    except :
        break
    
C2 = list()
D2 = list()

while True :
    try :
        c, d = map(int, input().split(","))
        C2.append(c)
        D2.append(d)
    except :
        break
    
C1_u = list(set(C1))
A = list()

for i in range(len(C1_u)) :
    cnt1 = C1.count(C1_u[i])
    cnt2 = C2.count(C1_u[i])
    if(cnt2 != 0) :
        A.append((C1_u[i], cnt1 + cnt2))
    else :
        pass
    
for i in range(len(A)) :
    print(A[i][0], A[i][1])

Submission status: Accepted

Solution code:
t1 = [0]*1001
t2 = [0]*1001

while 1:
    try:
        a, b = map(int, input().split(','))
        t1[a] += 1
    except:
        break

while 1:
    try:
        a, b = map(int, input().split(','))
        t2[a] += 1
    except:
        break

for i in range(1001):
    if t1[i] > 0 and t2[i] > 0:
        print(i, t1[i]+t2[i])

Submission status: Accepted

Solution code:

if __name__ == '__main__':
    
    A = set()
    B = set()
    C = []
    sw = False
    ans = []
    
    while True:
        try:
            line = input()
            if len(line) == 0:
                sw = True
            else:
                a,b = map(int,line.split(","))
                if sw:
                    B.add(a)
                else:
                    A.add(a)
                ans.append(a)
        except EOFError:
            break
            
    C = list(A & B)
    C.sort()

    for i in C:
        cnt = ans.count(i)
        print(i,cnt)

Submission status: Accepted

Solution code:
month_1={}
month_2={}
answer=[]
while 1:
    try:c,d=map(int,input().split(","))
    except:break
    if c in month_1:month_1[c] +=1
    else:month_1[c]=1
while 1:
    try:c,d=map(int,input().split(","))
    except:break
    if c in month_2:month_2[c] +=1
    else:month_2[c]=1
for v,m in month_1.items():
    if v in month_2:
        answer.append([v,month_1[v]+month_2[v]])
answer=sorted(answer)
for i in answer:
    print(i[0],i[1])

Submission status: Accepted

Solution code:
com=[0]*1001
chk=[]
while 1:
    try:
        n=list(map(int,input().split(",")))
        com[n[0]]+=1
    except:break
while 1:
    try:
        n=list(map(int,input().split(",")))
        if com[n[0]]>0:
            com[n[0]]+=1
            chk.append(n[0])
    except:break
chk_i=list(set(chk))
chk_i.sort()
for i in chk_i:
    print(i,com[i])

Submission status: Accepted

Solution code:
cus1 = [1 for i in range(1001)]
cus2 = [1 for i in range(1001)]
sum_ = dict(zip([i+1 for i in range(1000)],[0 for i in range(1000)]))
while(1):
    input_ = input()
    if input_ == "":
        break
    a,b = [int(i) for i in input_.split(",")]
    cus1[a] *= 0
    sum_[a] += 1
while(1):
    try:
        a,b = [int(i) for i in input().split(",")]
        cus2[a] *= 0
        sum_[a] += 1
    except EOFError:
        break
for i in range(1,1001):
    if cus1[i] + cus2[i] == 0:
        print(i,sum_[i])

Submission status: Accepted

Solution code:
clist1 = []
dlist1 = []
while 1:
    try:
        c, d = map(int, input().split(","))
    except:
        break

    clist1.append(c)
    dlist1.append(d)

clist2 = []
dlist2 = []
while 1:
    try:
        c, d = map(int, input().split(","))
    except:
        break

    clist2.append(c)
    dlist2.append(d)

clist1_unique = list(set(clist1))
clist1_unique.sort()

for c in clist1_unique:
    if c in clist2:
        count = clist1.count(c) + clist2.count(c)
        print(c, count)

Submission status: Runtime Error

Solution code:
#import math

listc = []
listd = {}
answer = []
n = 0

while True:
    s = input()
    if not s:
        break
    else:
        n += 1
        c,d = map(int,s.split(','))
    if c in listc:
        listd[c] += 1
    else:
        listc.append(c)
        listd[c] = 1

while n > 0:
    n -= 1
    c,d = map(int,input().split(','))
    if c in listc:
        if not c in answer:
            answer.append(c)
        listd[c] += 1

answer.sort()
for i in answer:
    print(i,listd[i])

Submission status: Runtime Error

Solution code:
old = []
new = []
ans = []
t = True

while True:
    n = input().split(',')[0]
    if n == '':
        if t:
            t = False
        else:
            break
    if t:
        old.append(n)
    else:
        new.append(n)


for o in set(old):
    if o in new:
        s = old.count(o) + new.count(o)
        ans.append([int(o), int(s)])
ans.sort()
for a in ans:
    print('%d %d' % (a[0], a[1]))

Submission status: Runtime Error

Solution code:
dict1 = {}
dict2 = {}

while True:
	str = raw_input().split(",")
	
	if len(str[0]) == 0:
		break
	
	if dict1.has_key(str[0]):
		dict1[str[0]] = dict1[str[0]] + 1
	else:
		dict1[str[0]] = 1
	
while True:
	str = raw_input().split(",")
	
	if len(str[0]) == 0:
		break
	
	if dict2.has_key(str[0]):
		dict2[str[0]] = dict2[str[0]] + 1
	else:
		dict2[str[0]] = 1

list = dict2.keys()

for var in list:
	dict1[var] = dict1[var] + dict2[var]
	print var, dict1[var]

Submission status: Runtime Error

Solution code:
dict1 = {}
dict2 = {}

while True:
	str = raw_input().split(",")
	
	if len(str[0]) == 0:
		break
	
	if dict1.has_key(str[0]):
		dict1[str[0]] = dict1[str[0]] + 1
	else:
		dict1[str[0]] = 1
	
while True:
	str = raw_input().split(",")
	
	if len(str[0]) == 0:
		break
	
	if dict2.has_key(str[0]):
		dict2[str[0]] = dict2[str[0]] + 1
	else:
		dict2[str[0]] = 1

list = sorted(dict2, reverse = True)
for var in list:
	dict1[var] = dict1[var] + dict2[var]
	print var, dict1[var]

Submission status: Runtime Error

Solution code:
dict1 = {}
dict2 = {}

while True:
	str = raw_input().split(",")
	
	if len(str[0]) == 0:
		break
	
	if dict1.has_key(str[0]):
		dict1[str[0]] = dict1[str[0]] + 1
	else:
		dict1[str[0]] = 1
	
while True:
	try:
		str = raw_input().split(",")
		
		if dict2.has_key(str[0]):
			dict2[str[0]] = dict2[str[0]] + 1
		else:
			dict2[str[0]] = 1
		
	except:
		break

list = sorted(dict2, reverse = True)
for var in list:
	dict1[var] = dict1[var] + dict2[var]
	print var, dict1[var]

Submission status: Runtime Error

Solution code:
dict1 = {}
dict2 = {}

while True:
	str = raw_input()
	if len(str[0]) == 0:
		break
	
	str.split(",")

	if dict1.has_key(str[0]):
		dict1[str[0]] = dict1[str[0]] + 1
	else:
		dict1[str[0]] = 1
	
while True:
	try:
		str = raw_input().split(",")
		
		if dict2.has_key(str[0]):
			dict2[str[0]] = dict2[str[0]] + 1
		else:
			dict2[str[0]] = 1
		
	except:
		break

list = sorted(set(dict1)&set(dict2), reverse = True)
for var in list:
	if(dict1[var] > 0 and dict2[var] > 0):
		print var, dict1[var] + dict2[var]

Submission status: Runtime Error

Solution code:
dict1 = {}
dict2 = {}

while True:
	log = raw_input()
	if len(log) == 0:
		break
	
	log = log.split(",")[0]
	
	if log in dict1:
		dict1[log] = dict1[log] + 1
	else:
		dict1[log] = 1
		
while True:
	try:
		log = raw_input()
		
		log = log.split(",")[0]
		
		if log in dict2:
			dict2[log] = dict2[log] + 1
		else:
			dict2[log] = 1
			
	except EOFError:
		break

list = dict1.keys()

for var in list:
	if dict1[var] > 0 and dict2[var] > 0:
		print var, dict1[var] + dict2[var]

Submission status: Runtime Error

Solution code:
flag = False
cli = [0] * 1000
sen = set()
kon = set()
while True:
    try:
        c, d = map(int, input().split(","))
    except:
        if flag:
            break
        flag = True
        continue
    if flag:
        kon.add(c)
    else:
        sen.add(c)
    cli[c] += 1

for i in range(1,1001):
    if i in sen and i in kon:
        print(i,cli[i])

Submission status: Runtime Error

Solution code:
dt = {}
def loop():
    while True:
        line = input()
        if line == '':
            break
        try:
            c, d = map(int, line.split(','))
            dt[c] = [d] if c not in dt else dt[c]+[d]
        except:
            break

loop()
loop()
for ab in sorted(dt.items(), key=lambda x: x[0]):
    a, b = ab[0], ab[1]
    if len(b) > 1:
        print(a, len(b))

Submission status: Runtime Error

Solution code:
dt = {}
def loop():
    while True:
        line = input()
        if line == '\n':
            break
        try:
            c, d = map(int, line.split(','))
            dt[c] = [d] if c not in dt else dt[c]+[d]
        except:
            break

loop()
loop()
for ab in sorted(dt.items(), key=lambda x: x[0]):
    a, b = ab[0], ab[1]
    if len(b) > 1:
        print(a, len(b))

Submission status: Runtime Error

Solution code:
import sys
b=0
a=[{},{}]
for e in sys.stdin:
 if'\n'==e:b=1
 else:c=int(e.split(',')[0])
  if c in a[b]:a[b][c]+=1
  else:a[b][c]=1
for k in sorted({*a[0]}&{*a[1]}):print(k,a[0][k]+a[1][k])

Submission status: Runtime Error

Solution code:
import sys
b=0
a=[{},{}]
for e in sys.stdin:
 if'\n'==e:b=1
 else:c=int(e.split(',')[0]);a[b][c]=1+[0,a[b][c]][c in a[b]]
for k in sorted({*a[0]}&{*a[1]}):print(k,a[0][k]+a[1][k])

Submission status: Runtime Error

Solution code:
import sys
b=0
a=[{},{}]
for e in sys.stdin:
 if'\n'==e:b=1
 else:c_=e.split(',');c=int(c);a[b].setdefault(c,0);a[b][c]+=1
for k in sorted({*a[0]}&{*a[1]}):print(k,a[0][k]+a[1][k])

Submission status: Runtime Error

Solution code:
import sys
C=range(1000)
f=0
d=[[0 for i in C] for j in range(2)]
for s in sys.stdin.readlines():
    if s=="\n":f+=1
    else:
        a,b=map(int,s.split(','))
        d[f][a]+=1
for i in C:
    a=d[0][i]
    b=d[1][i]
    if a!=0 and b!=0: print i, a+b

Submission status: Runtime Error

Solution code:
import sys
C=range(1000)
m=0
d=[[0 for i in C] for j in range(2)]
for s in sys.stdin.readlines():
    if s=="\n":m+=1
    else:
        a,b=map(int,s.split(','))
        d[m][a]+=1
for i in C:
    a=d[0][i]
    b=d[1][i]
    if a!=0 and b!=0:print i,a+b

Submission status: Runtime Error

Solution code:
from collections import Counter

cnt = 0
trade = Counter()
while 1:
    line = raw_input()
    if not line:
        break
    cnt += 1
    a, b = map(int, line.split(','))
    trade[a] += 1

for i in xrange(cnt):
    a, b = map(int, raw_input().split(','))
    trade[a] += 1

for k, v in sorted(trade.items()):
    print k, v