Problem:


ヒットアンドブロー

  太郎君と花子さんはヒットアンドブローで遊ぶことにしました。ヒットアンドブローのルールは、以下の通りです。

  
 出題者と回答者に分かれて行う。

  
 出題者は、重複した数を含まない 4 桁の数字(正解)を決める。

  
 回答者は、その 4 桁の数字(回答)を言い当てる。

  
 回答に対して、出題者はヒットとブローの数でヒントを与える。

  
 回答と正解を比べて、数と桁位置の両方が同じであることをヒットと呼び、数だけが同じで桁位置が異なることをブローと呼ぶ。たとえば、正解が 1234 で、回答が 1354 なら、出題者は「2 ヒット、1 ブロー」というヒントを与え、正解までこれを繰り返す。

  
 出題者と回答者は交代してゲームを行い、より少ない回答で正解を言い当てた方を勝ちとする。

太郎君と花子さんは、ヒットの数とブローの数をその都度判断することが少し面倒に感じているようです。そんな二人のために、ヒットの数とブローの数が即座に分かるプログラムを作成してあげましょう。

  正解 r と回答 a を入力とし、ヒットの数とブローの数を出力するプログラムを作成してください。r、a はそれぞれ 0 から 9 の数字 4 つからなる数字の列です。

Input

複数のデータセットの並びが入力として与えられます。入力の終わりはゼロふたつの行で示されます。各データセットとして、r と a が空白区切りで１行に与えられます。

データセットの数は 12000 を超えません。

Output

入力データセットごとに、ヒットの数とブローの数を１行に出力します。

Sample Input

1234 5678
1234 1354
1234 1234
1230 1023
0123 1234
0 0

Output for the Sample Input

0 0
2 1
4 0
1 3
0 3



Sample input:
1234 5678
1234 1354
1234 1234
1230 1023
0123 1234
0 0


Sample output:
0 0
2 1
4 0
1 3
0 3

Submission status: Wrong Answer

Solution code:
while True:
    r,a = list(input().split(" "))

    if r == "0" and a == "0":
        break

    r_list = [int(s) for s in list(r)]
    a_list = [int(s) for s in list(a)]

    hit_count = 0
    blow_count = 0
    for i in range(0,len(a_list)):
        if r_list[i] == a_list[i]:
            hit_count += 1
            a_list[i] = -1
            r_list[i] = -1
    while -1 in a_list:
        a_list.remove(-1)

    for i in range(0,len(a_list)):
        if a_list[i] in r_list:
            blow_count += 1
            r_list[i] = -1
    print(hit_count,blow_count)

Submission status: Wrong Answer

Solution code:
while True:
    r,a = list(input().split(" "))

    if r == "0" and a == "0":
        break

    r_list = [int(s) for s in list(r)]
    a_list = [int(s) for s in list(a)]

    hit_count = 0
    blow_count = 0
    for i in range(0,len(a_list)):
        if r_list[i] == a_list[i]:
            hit_count += 1
            a_list[i] = -1
            r_list[i] = -1
    while -1 in a_list:
        a_list.remove(-1)

    for i in range(0,len(a_list)):
        if a_list[i] in r_list:
            blow_count += 1
            r_list[i] = -1
    print(str(hit_count) + str(blow_count))

Submission status: Wrong Answer

Solution code:
answer_list = []
while True:
    r,a = list(input().split(" "))

    if r == "0" and a == "0":
        break

    r_list = [int(s) for s in list(r)]
    a_list = [int(s) for s in list(a)]

    hit_count = 0
    blow_count = 0

    for i in range(0,len(a_list)):
        if r_list[i] == a_list[i]:
            hit_count += 1
            a_list[i] = -1
            r_list[i] = -1
    while -1 in a_list:
        a_list.remove(-1)

    for i in range(0,len(a_list)):
        if a_list[i] in r_list:
            blow_count += 1
            r_list[i] = -1
    answer_list.append(str(hit_count) + " " + str(blow_count))
for ans in answer_list:
    print(ans)

Submission status: Wrong Answer

Solution code:

while True:
    r,a = list(input().split(" "))

    if r == "0" :
        break


    r_list = [int(s) for s in list(r)]
    a_list = [int(s) for s in list(a)]

    hit_count = 0
    blow_count = 0

    for i in range(0,len(a_list)):
        if r_list[i] == a_list[i]:
            hit_count += 1
            a_list[i] = -1
            r_list[i] = -1
    while -1 in a_list:
        a_list.remove(-1)

    for i in range(0,len(a_list)):
        if a_list[i] in r_list:
            blow_count += 1
            r_list[i] = -1
    print ('%d %d' % (hit_count,blow_count))

Submission status: Wrong Answer

Solution code:



if __name__ == '__main__':


    while True:

        a,b = map(str,raw_input().split(' '))

        if a == '0' and b == '0':
            break

        print a,b

        a = list(a)
        b = list(b)
    #    print a


        br = 0
        hit = 0
        for i,data in enumerate(b):

            if data in a:
                if a[i] == data:
                    hit += 1

                else:
                    br += 1

        print hit,br

Submission status: Accepted

Solution code:
while True:

    a, b = input().split()

    if a == "0" and b == "0":
        break

    a1 = 0
    a2 = 0

    for i in range(4):
        if a[i] == b[i]:
            a1 += 1

    for i in range(4):
        for j in range(4):
            if a[i] == b[j]:
                a2 += 1

    print(a1, a2-a1)

Submission status: Accepted

Solution code:
while 1:
    x,y = map(list,input().split())
    if x == ['0'] and y== ['0']: break

    h = b = 0
    for i in range(len(x)):
        if x[i] == y[i]:
            h += 1
        elif y[i] in x:
            b += 1

    print ('%d %d' % (h,b))

Submission status: Accepted

Solution code:
import sys
f = sys.stdin

while True:
    r, a = f.readline().strip().split()
    if r == '0':
        break
    hit = sum(1 for ri, ai in zip(r, a) if ri == ai)
    blow = sum(1 for ai in a if ai in r) - hit

    print(hit, blow)

Submission status: Accepted

Solution code:
while True:
    r, a = raw_input().split()
    if r == a == '0': break
    h = 0
    _r = []
    _a = []
    for i in range(4):
        if a[i] == r[i]:
            h += 1
        else:
            _r.append(r[i])
            _a.append(a[i])
    else:
        print h, len(set(_r)&set(_a))

Submission status: Accepted

Solution code:
while True:
    r, a= input().split()
    if r==a=='0': break
    print(sum(1 for i, j in zip(r, a) if i==j), sum(1 for i in range(len(r)) for j in range(len(a)) if r[i]==a[j] and i!=j))

Submission status: Accepted

Solution code:
while 1:
    a,b=list(input().split())
    if len(a)==1:break
    h=0
    for i,j in zip(a,b):h+=i==j
    print(h,len(set(a)&set(b))-h)

Submission status: Accepted

Solution code:
while 1:
    a,b=input().split()
    if a=='0':break
    h=0
    for i,j in zip(a,b):h+=i==j
    print(h,len(set(a)&set(b))-h)

Submission status: Accepted

Solution code:
# Aizu Problem 0226: Hit and Blow

import sys, math, os, bisect

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


def hit_and_blow(seq, guess):
    hit, blow = 0, 0
    nums = list(range(10))
    for k in range(4):
        s = seq
        if seq[k] == guess[k]:
            hit += 1
            nums.remove(int(seq[k]))
    blow = sum([str(n) in guess and str(n) in seq for n in nums])
    return hit, blow
            

while True:
    seq, guess = [_ for _ in input().split()]
    if seq == guess == "0":
        break
    hit, blow = hit_and_blow(seq, guess)
    print(hit, blow)

Submission status: Accepted

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

"""
import sys
from sys import stdin
input = stdin.readline


def solve(r, a):
    hit = 0
    blow = 0

    for i in range(4):
        if r[i] == a[i]:
            hit += 1
        else:
            if a[i] in r:
                blow += 1
    return hit, blow


def main(args):
    while True:
        r, a = input().split()
        if r == '0' and a == '0':
            break
        hit, blow = solve(r, a)
        print(hit, blow)


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

Submission status: Accepted

Solution code:
for q in range(12000):
    a, b = input().split()
    if a[0] is '0' and b[0] is '0':
        break

    hit = 0
    for i in range(4):
        if a[i] is b[i]:
            hit = hit + 1

    blow = 0
    for j in range(4):
        for i in range(4):
            if (b[j] is a[i]) and (a[i] is not b[i]) and (a[j] is not b[j]):
                blow = blow + 1

    print(hit, blow)

Submission status: Accepted

Solution code:
for q in range(12000):
    a, b = input().split()
    if a[0] is '0' and b[0] is '0':
        break

    hit = sum(1 for c, d in zip(a, b) if d is c)
    blow = sum(1 for e in b if e in a) - hit
    print(hit, blow)

Submission status: Accepted

Solution code:
while True:
    a, b = input().split()
    if a[0] is '0' and b[0] is '0':
        break
 
    hit = sum(1 for c, d in zip(a, b) if d is c)
    blow = sum(1 for e in b if e in a) - hit
    print(hit, blow)

Submission status: Accepted

Solution code:
# AOJ 0226: Hit and Blow
# Python3 2018.6.23 bal4u

while 1:
	r, a = input().split()
	if r == '0': break
	h, sr, sa = 0, set(), set()
	for i in range(4):
		if r[i] == a[i]: h += 1
		else:
			sr.add(r[i])
			sa.add(a[i])
	print(h, len(sr & sa))

Submission status: Accepted

Solution code:
# AOJ 0226: Hit and Blow
# Python3 2018.6.25 bal4u

while 1:
	r, a = input().split()
	if r == '0': break
	h = 0
	for i in range(4):
		if r[i] == a[i]: h += 1
	print(h, len(set(r) & set(a))-h)

Submission status: Accepted

Solution code:
while True:
  r, a = input().split()
  if r == "0":
    break
  
  hit = 0
  for x, y in zip(r, a):
    if x == y:
      hit += 1
  
  blow = -hit
  for x in r:
    if x in a:
      blow += 1

  print(hit, blow)

Submission status: Accepted

Solution code:
while True:
  a = raw_input()
  if int(a[0]) == 0 and int(a[2]) == 0: break
  b =[]
  hit=0
  blow=0
  for i in range(5,9):
    b.append(a[i])
  for x in range(0,4):
    for y in range(0,4):
      if a[x] == b[y]:
        if x == y:
          hit +=1
        else: blow +=1
  print hit,blow

Submission status: Accepted

Solution code:
while True:
    a,b=raw_input().split()
    if a==b=="0":break
    hit,blow=0,0
    for i,j in zip(a,b):
        if i==j:
            hit+=1
    for i in a:
        if i in b:
            blow+=1
    print hit,blow-hit

Submission status: Accepted

Solution code:
while True:
    a,b=raw_input().split()
    if a==b=="0":break
    hit=sum(1 for i,j in zip(a,b) if i==j)
    blow=sum(1 for i in a if i in b)
    print hit,blow-hit

Submission status: Accepted

Solution code:



if __name__ == '__main__':


    while True:

        a,b = map(str,raw_input().split(' '))

        if a == '0' and b == '0':
            break

      #  print a,b

        a = list(a)
        b = list(b)
    #    print a


        br = 0
        hit = 0
        for i,data in enumerate(b):

            if data in a:
                if a[i] == data:
                    hit += 1

                else:
                    br += 1

        print hit,br

Submission status: Accepted

Solution code:
while 1:
    r,a=raw_input().split()
    if r=='0' and a=='0': break
    h = b = 0
    for i in xrange(4):
        if r[i]==a[i]: h+=1
    for i in xrange(10):
        b += min(r.count(chr(ord('0')+i)),a.count(chr(ord('0')+i)))
    print h,b-h

Submission status: Accepted

Solution code:
while 1:
    r,a=raw_input().split()
    if r=='0' and a=='0': break
    h = b = 0
    for i in xrange(4):
        if r[i]==a[i]: h+=1
    for s in r:
        for t in a:
            if s==t:
                b+=1; break;
    print h,b-h

Submission status: Accepted

Solution code:
while True:
    r, a = raw_input().split()
    if (r,a) == ("0","0"):
        break
    h = len([1 for i in xrange(4) if a[i] == r[i]])
    b = len([1 for i in xrange(4) if a[i] in r])
    print h, b - h

Submission status: Accepted

Solution code:
while 1:
	m,n=map(str,raw_input().split())
	if m=="0":break
	h=b=0
	for i in range(4):
		if m[i]==n[i]:h+=1
		elif m[i] in n:b+=1
	print h,b

Submission status: Accepted

Solution code:
while True :
    a, b = map(int, input().split())
    if a == 0 and b == 0 :
        break
    
    hit = 0
    blow = 0
    if a//1000 == b//1000 :
        hit += 1
    if (a%1000)//100 == (b%1000)//100 :
        hit += 1
    if (a%100)//10 == (b%100)//10 :
        hit += 1
    if a%10 == b%10 :
        hit += 1
    if a//1000 == (b%1000)//100 or a//1000 == (b%100)//10 or a//1000 == b%10 :
        blow += 1
    if (a%1000)//100 == b//1000 or (a%1000)//100 == (b%100)//10 or (a%1000)//100 == b%10 :
        blow += 1
    if (a%100)//10 == b//1000 or (a%100)//10 == (b%1000)//100 or (a%100)//10 == b%10 :
        blow += 1
    if a%10 == b//1000 or a%10 == (b%1000)//100 or a%10 == (b%100)//10 :
        blow += 1
    print(hit, blow)

Submission status: Accepted

Solution code:
while True:
    a,b = input().split()
    if a == b == "0":
        break
    count = 0
    for i in range(4):
        if a[i] == b[i]:
            count += 1
    print(count,end = " ")
    newcount = 0
    for j in range(4):
        if a[j] == b[0] or a[j] == b[1] or a[j] == b[2] or a[j] == b[3]:
            newcount += 1
    print(newcount - count)

Submission status: Accepted

Solution code:
while True:
    s, t = input().split()
    if s == "0" and t == "0":
        break
    
    S = [int(x) for x in list(s)]
    T = [int(x) for x in list(t)]
    
    hit = 0
    blow = 0
    for i in range(len(T)):
        if T[i] in S:
            blow += 1
        if T[i] == S[i]:
            blow -= 1
            hit  += 1
    
    print(hit, blow)

Submission status: Accepted

Solution code:
while True:
    A,B = map(list, input().split())
    if len(A) == 1:
        break
    hit=0
    blowPlusHit=0
    for i in range(4):
        if A[i] == B[i]:
            hit+=1
        for j in range(4):
            if A[i]==B[j]:
                blowPlusHit += 1
    print(f"{hit} {blowPlusHit-hit}")

Submission status: Accepted

Solution code:
while True:
    hit=0
    bur=0
    a,una=(input().split())
    if a=='0' and una=='0':
        break
    a=list(a)
    una=list(una)
    for k in range(4):
        if a[k]==una[k]:
            hit+=1
    for d in range(4):
        for s in range(4):
            if a[d]==una[s]:
                bur+=1
    print(str(hit)+' '+str(bur-hit))

Submission status: Accepted

Solution code:
while True:
  r, a = input().split()
  if r == "0":
    break
   
  h = 0
  for x, y in zip(r, a):
    if x == y:
      h += 1
   
  b = -h
#  print(b)
  for x in r:
    if x in a:
      b += 1
 
  print(h, b)

Submission status: Accepted

Solution code:
while 1:
    a,b=input().split()
    if a=='0':break
    h=0
    for i,j in zip(a,b):h+=i==j
    print(h,len(set(a)&set(b))-h)

Submission status: Accepted

Solution code:
# AOJ 0226: Hit and Blow
# Python3 2018.6.25 bal4u
 
while 1:
    r, a = input().split()
    if r == '0': break
    h = 0
    for i in range(4):
        if r[i] == a[i]: h += 1
    print(h, len(set(r) & set(a))-h)

Submission status: Accepted

Solution code:
while 1:
    r, a = map(int, input().split())
    if r == 0:
        break

    pro = list(str(r).zfill(4))
    ans = list(str(a).zfill(4))

    hit = 0
    blow = 0
    for p, a in zip(pro, ans):
        if p == a:
            hit += 1
        elif a in pro:
            blow += 1

    print(hit, blow)

Submission status: Accepted

Solution code:
while True:
    r, a = input().split()
    if r == a == '0': break
    h, b = 0, 0
    for i in range(4):
        if r[i] == a[i]:
            h += 1
        elif a[i] in r:
            b += 1
    print(h, b)

Submission status: Runtime Error

Solution code:
while True:
    r, a = raw_input().split()
    if r == a == 0: break
    h = 0
    _r = []
    _a = []
    for i in range(4):
        if a[i] == r[i]:
            h += 1
        else:
            _r.append(r[i])
            _a.append(a[i])
    else:
        print h, len(set(_r)&set(_a))

Submission status: Runtime Error

Solution code:
while True:
    r, a= input().split()
    if r==a==0: break
    print(sum(1 for i, j in zip(r, a) if i==j), sum(1 for i in range(len(r)) for j in range(len(a)) if r[i]==a[j] and i!=j))

Submission status: Runtime Error

Solution code:
for q in range(12000):
    a = tuple(map(int, input().split()))
    b = input()
    if a[0] == 0 and b[0] == '0':
        break

    hit = 0
    for i in range(4):
        if a[i] == int(b[i]):
            hit = hit + 1

    blow = 0
    for j in range(4):
        for i in range(4):
            if (int(b[j]) == a[i]) and (a[i] != int(b[i])) and (a[j] != int(b[j])):
                blow = blow + 1

    print(hit, blow)

Submission status: Runtime Error

Solution code:
while True:
 aw=[]
 ar = raw_input()
 if ar[0] ==0 and ar[1] ==0 and ar[2] ==0: break
 else:
  hit=0
  blo=0
  for t in range(5,9):
    aw.append(ar[t])
  for t in range(0,4):
    if ar[t] == aw[t]: hit+=1
  for t in range(0,4):
    for y in range(0,4):
      if ar[t] == aw[y]:
        if t == y: break
        else: blo +=1
  print hit,blo

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':


    while True:
        
        a,b = map(str,raw_input().split(' '))
    
        if a == 0 and b == 0:
            break 

        a = list(a)
        b = list(b)
    #    print a


        br = 0
        hit = 0
        for i,data in enumerate(b):

            if data in a:
                if a[i] == data:
                    hit += 1

                else:
                    br += 1

        print hit,br