Problem:


病院の部屋番号 

  ウォーターデブンに住む建築家のデブンキーさんのもとに、古い大病院を改装する仕事の依頼が舞い込んできました。

  国によっては忌み数(いみかず)として嫌われる数字を部屋番号に用いたくない人がいます(日本では 4 と 9 が有名です)。しかし、この病院の部屋番号は忌み数に関係なく、1 から順番に付けられていました。

  それが気になったデブンキーさんは、機材やベッドの入れ替えが全て終わる前にウォーターデブンの忌み数である「4」と「6」を除いた数字で部屋番号を付けなおしてしまいました。しかし、入れ替え作業は旧部屋番号で計画していたので、残りの作業を確実に行うには旧部屋番号を新部屋番号に変換する必要があります。計算が苦手なデブンキーさんはこのことに気づいて愕然としています。

  そんなデブンキーさんのために、旧部屋番号を入力とし対応する新部屋番号を出力するプログラムを作成してください。

15 番目までの部屋番号の対応表は以下のようになります。

旧部屋番号 1 2 3 4 5 6 7 8  9  10  11 12 13 14 15

新部屋番号 1 2 3 5 7 8 9 10 11 12 13 15 17 18 19

Input

複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。
各データセットとして、旧部屋番号を表す整数 n (1 ≤ n ≤ 1,000,000,000) が１行に与えられます。

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

Output

入力データセットごとに、新部屋番号を１行に出力します。

Sample Input

15
100
1000000000
3
0

Output for the Sample Input

19
155
9358757000
3



Sample input:
15
100
1000000000
3
0


Sample output:
19
155
9358757000
3

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
if n%8==0 or n%8==1 or n%8==2 or n%8==3:
    print int(oct(n))
elif n%8==4 :
    print int(oct(n)) + 1
elif n%8==5 or n%8==6 or n%8==7:
    print int(oct(n)) + 2

Submission status: Wrong Answer

Solution code:
while True:
    try:
        n = int(raw_input())
    except EOFError:
        break
    if n%8==0 or n%8==1 or n%8==2 or n%8==3:
        print int(oct(n))
    elif n%8==4 :
        print int(oct(n)) + 1
    elif n%8==5 or n%8==6 or n%8==7:
        print int(oct(n)) + 2

Submission status: Wrong Answer

Solution code:
while True:
    n = input()
    if n == '0':
        break
    if n[-1] in ('7', '8', '9'):
        print(int(n)-((len(n)-1)*2+2))
    elif n[-1] == '5':
        print(int(n)-((len(n)-1)*2+1))
    else:
        print(int(n)-(len(n)-1)*2)

Submission status: Wrong Answer

Solution code:
while True:
	i = int(raw_input())
	if i == 0:
		exit()
	f = (i+6)/10
	n = (i+1)/10
	print i-f-n

Submission status: Wrong Answer

Solution code:
inputlist=[]
while 1:
	inputnum=int(raw_input())
	if(inputnum==0):break
	inputlist.append(inputnum)
def octnpower(num):
	flag=0
	maxi=0
	maxj=0
	if(num<8):
		temp[0]=num
		return
	for i in range(1,11):
		for j in range(1,8):
			if(num>=(8**i)*j):
				flag=(8**i)*j
				maxi=i
				maxj=j
			else:
				temp[maxi]=maxj
				return octnpower(num-flag)

octdictionary={0:0,1:1,2:2,3:3,4:5,5:7,6:8,7:9}
for i in range(len(inputlist)-1):
	temp=[0]*10
	octnpower(inputlist[i])
	temp.reverse()
	for j in range(len(temp)):
		index=j
		if(temp[j]!=0):break
	temp=temp[index:]
	for j in range(len(temp)):
		temp[j]=octdictionary[temp[j]]
	ansstr=""
	for j in range(len(temp)):
		ansstr+=str(temp[j])
	print ansstr

Submission status: Wrong Answer

Solution code:
inputlist=[]
while 1:
	inputnum=int(raw_input())
	if(inputnum==0):break
	inputlist.append(inputnum)
def octnpower(num):
	flag=0
	maxi=0
	maxj=0
	if(num<8):
		temp[-1]=num
		return
	for i in range(1,11):
		for j in range(1,8):
			if(num>=(8**i)*j):
				flag=(8**i)*j
				maxi=i
				maxj=j
			else:
				temp[-maxi-1]=maxj
				return octnpower(num-flag)

octdictionary={0:0,1:1,2:2,3:3,4:5,5:7,6:8,7:9}
for i in range(len(inputlist)):
	temp=[0]*10
	octnpower(inputlist[i])
	print temp
	#temp.reverse()
	for j in range(len(temp)):
		index=j
		if(temp[j]!=0):break
	temp=temp[index:]
	for j in range(len(temp)):
		temp[j]=octdictionary[temp[j]]
	ansstr=""
	for j in range(len(temp)):
		ansstr+=str(temp[j])
	print ansstr

Submission status: Time Limit Exceeded

Solution code:
while True:
    num = int(input())

    index = 1
    for n in range(1, num):
        index += 1

        while True:
            str_index = str(index)
            if '4' in str_index or '6' in str_index:
                index += 1
            else:
                break

    print(index)

Submission status: Time Limit Exceeded

Solution code:
#Room Numbers of a Hospital
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0208
#coding: utf-8

num = 1;
sub = 0;
while 0 != num:
    num = int(input());
    f = 0;

    if num == 0:
        break;

    for i in range(1,num+1):
        sub = i % 10;
        if 4 == sub:
            f += 1;
        elif 6 == sub:
            f += 1;
        elif 4 == f % 10:
            f += 1;
        elif 6 == f % 10:
            f += 1;
        f += 1;
    print(f);

Submission status: Time Limit Exceeded

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    cnt = 1
    for i in range(1, n+1):
        tmp = str(cnt)
        while '4' in tmp or '6' in tmp:
            if '4' in tmp and '6' in tmp:
                l = min(tmp.find('4'), tmp.find('6'))
                r = len(tmp[l+1:])
                cnt += 1*pow(10, r)
            elif '4' in tmp:
                l = tmp.find('4')
                r = len(tmp[l+1:])
                cnt += 1*pow(10, r)
            else:
                l = tmp.find('6')
                r = len(tmp[l+1:])
                cnt += 1*pow(10, r)
            tmp = str(cnt)
        cnt += 1
    print(cnt-1)

Submission status: Time Limit Exceeded

Solution code:
while True:
    a=input()
    if a==0:break
    b=range(1,a+1)
    while True:
        d=[i for i in b if '4' in str(i) or '6' in str(i)]
        if len(d)==0:break;
        b=range(b[-1]+1,b[-1]+len(d)+1)
    print b[-1]

Submission status: Time Limit Exceeded

Solution code:
while True:
    n = int(raw_input())
    if n == 0:
        break
    c = 0
    key = 0
    while c < n:
        sc = str(key+1)
        if sc.count("4") + sc.count("6") > 0:
            key += 1
        else:
            c += 1
            key += 1
    print key

Submission status: Time Limit Exceeded

Solution code:
while True:
    n = int(raw_input())
    if n == 0:
        break
    c = 0
    key = 0
    while c < n:
        sc = list(set(str(key+1)))
        if sc.count("4") or sc.count("6"):
            key += 1
        else:
            c += 1
            key += 1
    print key

Submission status: Time Limit Exceeded

Solution code:
while True:
	n = int(raw_input())
	ans = 0
	if n == 0: break
	for i in range(n):
		ans += 1
		while '4' in str(ans) or '6' in str(ans):
			ans += 1
	print ans

Submission status: Memory Limit Exceeded

Solution code:
newnum = []
j = 1
i = 0
while i < 1000000000:
    num = str(j)
    nl = list(num)
    j += 1
    if "4" in nl or "6" in nl:
        continue
    newnum.append(nl)
    i += 1

while True:
    n = input()
    if n == 0:
        break
    print "%s" % "".join(newnum[n-1])

Submission status: Accepted

Solution code:
def base10to8(n):

    ans = ""
    while n > 0:
        ans = str(n % 8) + ans
        n = n // 8

    return ans


while True:

    n = int(input())
    if n == 0:
        break

    s = base10to8(n)

    table = [0,1,2,3,5,7,8,9]
    for i in range(len(s)):
        print(table[int(s[i])], end="")
    print("")

Submission status: Accepted

Solution code:
digit = [0, 1, 2, 3, 5, 7, 8, 9]
n = input()
while n != 0:
    new_num = []
    eight = 1
    
    while eight * 8 <= n:
        eight *= 8
    while eight > 0:
        new_num.append(n / eight)
        n %= eight
        eight /= 8
    
    nn_str = ''
    for i in range(0, len(new_num)):
        nn_str += str(digit[new_num[i]])
    print nn_str
    n = input()

Submission status: Accepted

Solution code:
from sys import stdin
readline = stdin.readline


while True:
    old_room_num = int(readline())
    if old_room_num == 0:
        break
    octal = oct(old_room_num)[2:]
    new_room_num = octal.translate(str.maketrans('4567', '5789'))
    print(new_room_num)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
while True:
  x=oct(input())[1:].replace('7','9').replace('6','8').replace('5','7').replace('4','5')
  if x=='': break
  print x

Submission status: Accepted

Solution code:
taboo = ["0", "1", "2", "3", "5", "7", "8", "9"]
while True:
	n = input()
	if n == 0 : break

	room = ""	
	for i in oct(n)[1:]:
		room += taboo[int(i)]
		
	print room

Submission status: Accepted

Solution code:
while True:
    n = input()
    if n == 0:
        break
    n8 = oct(n)
    tmp = list(n8)
    strlen = len(tmp)
    for i in range(strlen):
        if tmp[i] == "4":
            tmp[i] = "5"
        elif tmp[i] == "5":
            tmp[i] = "7"
        elif tmp[i] == "6":
            tmp[i] = "8"
        elif tmp[i] == "7":
            tmp[i] = "9"
    print "%s" % "".join(tmp)[1:]

Submission status: Accepted

Solution code:
""" Created by Jieyi on 9/20/16. """


def main():
    while True:
        num = int(input())
        if num == 0:
            break

        num = str(oct(num)[2:])
        ans = num.translate(str.maketrans('4567', '5789'))
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
while 1:
    n=int(input())
    if n==0:break
    n=str(oct(n)[2:])
    n=n.translate(str.maketrans('4567','5789'))
    print(n)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    print(str(oct(n)[2:]).translate(str.maketrans("4567", "5789")))

Submission status: Accepted

Solution code:
# Aizu Problem 0208: Room Numbers of a Hospital

import sys, math, os

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


    
while True:
    n = int(input())
    if n == 0:
        break
    print(oct(n)[2:].replace('7','9').replace('6','8').replace('5','7').replace('4','5'))

Submission status: Accepted

Solution code:
while(1):
  n = int(input())
  if n == 0:
    break
  print(oct(n)[2:].translate(str.maketrans('4567', '5789')))

Submission status: Accepted

Solution code:
while 4:
    n=int(input())
    if n==0:break
    print(oct(n)[2:].translate(str.maketrans("4567","5789")))

Submission status: Accepted

Solution code:
from sys import stdin
for i in stdin:
    if i=="0\n":break
    print(oct(int(i))[2:].translate(str.maketrans("4567","5789")))

Submission status: Accepted

Solution code:
from sys import stdin
line=stdin.readlines()
for i in line[:-1]:print(oct(int(i))[2:].translate(str.maketrans("4567","5789")))

Submission status: Accepted

Solution code:
from sys import stdin
l=stdin.readlines()
for i in l[:-1]:print(oct(int(i))[2:].translate(str.maketrans("4567","5789")))

Submission status: Accepted

Solution code:
import sys
l=sys.stdin.readlines()
for i in l[:-1]:print(oct(int(i))[2:].translate(str.maketrans("4567","5789")))

Submission status: Accepted

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

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


def solve(num):
    ans = []
    o_txt = oct(num)[2:]

    for o in o_txt:
        if int(o) >= 6:
            ans.append(int(o) + 2)
        elif int(o) == 5:
            ans.append(7)
        elif int(o) >= 4:
            ans.append(int(o) + 1)
        else:
            ans.append(int(o))
    return ans


def main(args):
    while True:
        num = int(input())
        if num == 0:
            break
        ans = solve(num)
        print(*ans, sep='')


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

Submission status: Accepted

Solution code:
def testcase_ends():
    n = int(input())
    if n == 0:
        return 1

    n = oct(n)[2:]
    n = n.replace('7', '9')
    n = n.replace('6', '8')
    n = n.replace('5', '7')
    n = n.replace('4', '5')
    print(n)
    return 0

def main():
    while not testcase_ends():
        pass

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def testcase_ends():
    n = int(input())
    if n == 0:
        return 1

    n = oct(n)[2:]
    print(*['01235789'[int(i)] for i in n], sep='');
    return 0

def main():
    while not testcase_ends():
        pass

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
print(*[''.join('01235789'[int(i)]for i in oct(int(x))[2:])for x in open(0).read().split()[:-1]],sep='\n')

Submission status: Accepted

Solution code:
while(1):
    n = int(input())
    if(not n):
        break
    print("".join("01235789"[int(i)] for i in oct(n)[2:]))

Submission status: Accepted

Solution code:
while(1):
    n = int(input())
    if(not n):
        break
    print("".join("01235789"[int(i)] for i in oct(n)[2:]))

Submission status: Accepted

Solution code:
def ge(arr):
    for i in range(len(arr)):
        tmp = int(arr[i])
        if tmp >= 4:
            tmp += 1
        if tmp >= 6:
            tmp += 1
        arr[i] = str(tmp)
    return arr


while True:
    n = int(input())
    if n == 0:
        break
    print("".join(ge(list(oct(n))[2:])))

Submission status: Accepted

Solution code:
# AOJ 0208 Room Numbers of a Hospital
# Python3 2018.6.23 bal4u
# 8進数に変換して、01234567を01235789に置き換える

dic = {'0':'0','1':'1','2':'2','3':'3','4':'5','5':'7','6':'8','7':'9'}
while 1:
	n = int(input())
	if n == 0: break
	s = list(format(n, 'o'))
	for i in range(len(s)): s[i] = dic[s[i]]
	print(*s, sep='')

Submission status: Accepted

Solution code:
# AOJ 0208 Room Numbers of a Hospital
# Python3 2018.6.23 bal4u
# 8進数に変換して、01234567を01235789に置き換える

dic = {'0':'0','1':'1','2':'2','3':'3','4':'5','5':'7','6':'8','7':'9'}
while 1:
	n = int(input())
	if n == 0: break
	s = format(n, 'o')
	ans = ''
	for i in range(len(s)): ans += dic[s[i]]
	print(ans)

Submission status: Accepted

Solution code:
# AOJ 0208 Room Numbers of a Hospital
# Python3 2018.6.23 bal4u
# 8進数に変換して、01234567を01235789に置き換える

tbl = ('0','1','2','3','5','7','8','9')
while 1:
	n = int(input())
	if n == 0: break
	s = format(n, 'o')
	ans = ''
	for i in range(len(s)): ans += tbl[int(s[i])]
	print(ans)

Submission status: Accepted

Solution code:
dic = {"0":"0", "1":"1", "2":"2", "3":"3",
       "4":"5", "5":"7", "6":"8", "7":"9"}
def trans(n):
  if n == 0:
    return "0"
  acc = ""
  while n:
    acc += dic[str(n % 8)]
    n //= 8
  return acc[::-1]

while True:
  n = int(input())
  if n == 0:
    break
  print(trans(n))

Submission status: Accepted

Solution code:
conv = map(str, [0, 1, 2, 3, 5, 7, 8, 9])
while True:
	n = input()
	if not n: break
	result = ""
	for c in oct(n)[1:]:
		result += conv[int(c)]
	print result

Submission status: Accepted

Solution code:
while True:
    n=input()
    if n==0:break
    n=str(oct(n))
    S=[]
    for i in n[1:]:
        if i=="4":
            S.append("5")
        elif i>="5":
            S.append(str(int(i)+2))
        else:
            S.append(i)
    print "".join(S)

Submission status: Accepted

Solution code:
N = map(str,[0,1,2,3,5,7,8,9])
while True:
    n = input()
    if n == 0:
        break
    print "".join(map(lambda x:N[int(x)], oct(n)[1:]))

Submission status: Accepted

Solution code:
inputlist=[]
while 1:
	inputnum=int(raw_input())
	if(inputnum==0):break
	inputlist.append(inputnum)
def octnpower(num):
	flag=0
	maxi=0
	maxj=0
	if(num<8):
		temp[-1]=num
		return
	for i in range(1,11):
		for j in range(1,8):
			if(num>=(8**i)*j):
				flag=(8**i)*j
				maxi=i
				maxj=j
			else:
				temp[-maxi-1]=maxj
				return octnpower(num-flag)

octdictionary={0:0,1:1,2:2,3:3,4:5,5:7,6:8,7:9}
for i in range(len(inputlist)):
	temp=[0]*10
	octnpower(inputlist[i])
	for j in range(len(temp)):
		index=j
		if(temp[j]!=0):break
	temp=temp[index:]
	for j in range(len(temp)):
		temp[j]=octdictionary[temp[j]]
	ansstr=""
	for j in range(len(temp)):
		ansstr+=str(temp[j])
	print ansstr

Submission status: Accepted

Solution code:
ref = ["0","1","2","3","5","7","8","9"]
while True:
    n = int(raw_input())
    if n == 0: break
    ans = ""
    for i in str(oct(n))[1:]:
        ans += ref[int(i)]
    print ans

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

a={'0':'0','1':'1','2':'2','3':'3','4':'5','5':'7','6':'8','7':'9'}


while True:
    n=int(input())
    if n==0:
        break
    
    else:
        N=list(format(n,"o"))   #8進法
        
    for i in range(len(N)):
        print(a[N[i]],end="")
    print()

Submission status: Accepted

Solution code:
while True:
    x=int(input())
    if x==0:
        break
    x = oct(x)[2:]
    print(x.translate(str.maketrans('4567', '5789')))

Submission status: Accepted

Solution code:
while True:
  n = int(input())
  if n == 0:
    break
  n = oct(n)[2:]
  print(n.translate(str.maketrans('4567', '5789')))

Submission status: Accepted

Solution code:
def x(i):
    if i==0:
        return 0
    if i==1:
        return 1
    if i==2:
        return 2
    if i==3:
        return 3
    if i==4:
        return 5
    if i==5:
        return 7
    if i==6:
        return 8
    if i==7:
        return 9

while True:
    n = int(input())
    if n==0:
        break
    n = oct(n)
    n = list(n)
    del(n[0:2])
    for i in range(len(n)):
        print(x(int(n[i])),end='')
    print()

Submission status: Accepted

Solution code:
octD = {"0":0, "1":1, "2":2, "3":3, "4":5, "5":7, "6":8, "7":9}

while True :
    n = int(input())
    
    if n == 0 :
        break
    
    else :
        N = list(format(n, "o"))
        # nを8進数に変換
        
        for i in range(len(N)) :
            print(octD[N[i]], end = "")
        print()

Submission status: Accepted

Solution code:
import sys
  
#0123456789
#01234567
#01235789

def convert(dec):
    s = ""
    d = dec
    while True:
        div = d//8
        rem = d % 8
        d = div
        if rem == 4:
            rem = 5
        elif rem == 5:
            rem = 7
        elif rem == 6:
            rem = 8
        elif rem == 7:
            rem = 9

        s = str(rem)+ s
        if div <= 0:
            break
    return s

for s in sys.stdin:
    if int(s) == 0:
        break
    print(convert(int(s)))

Submission status: Accepted

Solution code:
while True:
  a=int(input())
  if a==0:
    break

  ans=oct(a)[2:]
  print(ans.translate(str.maketrans({"4":"5","5":"7","6":"8","7":"9"})))

Submission status: Accepted

Solution code:
while True:
  n = int(input())
  if(n == 0):
    break
  print(''.join('01235789'[int(i)] for i in oct(n)[2:]))

Submission status: Accepted

Solution code:
while True:
  n = int(input())
  if not n: break
  n = oct(n)[2:]
  print(n.translate(str.maketrans('4567', '5789')))

Submission status: Accepted

Solution code:
a = "0 1 2 3 5 7 8 9".split()
while True:
    N = int(input())
    if N == 0:
        break
    print("".join((a[int(n)] for n in oct(N)[2:])))

Submission status: Accepted

Solution code:
from sys import stdin
while(True):
    n = int(stdin.readline())
    if not n:
        break
    print(str(oct(n))[2:].translate(str.maketrans('4567','5789')))

Submission status: Accepted

Solution code:
while 1:
    c=input()
    if c=="0":break
    print(format(int(c),'o').translate(str.maketrans({"4":"5","5":"7","6":"8","7":"9"})))

Submission status: Runtime Error

Solution code:
while(1):print(oct(n)[2:].translate(str.maketrans('4567', '5789')))

Submission status: Runtime Error

Solution code:
def ge(arr):
    for i in range(len(arr)):
        tmp = int(arr[i])
        if tmp >= 4:
            tmp += 1
        if tmp >= 6:
            tmp += 1
        arr[i] = str(tmp)


while True:
    n = int(input)
    if n == 0:
        break
    print("".join(ge(list(oct(n))[2:])))

Submission status: Runtime Error

Solution code:
inputlist=[]
while 1:
	inputnum=int(raw_input())
	if(inputnum==0):break
	inputlist.append(inputnum)
def octnpower(num):
	flag=0
	maxi=0
	maxj=0
	if(num<8):
		temp[0]=num
		return
	for i in range(1,11):
		for j in range(1,8):
			if(num>=(8**i)*j):
				flag=(8**i)*j
				maxi=i
				maxj=j
			else:
				temp[maxi]=maxj
				return octnpower(num-flag)

octdictionary={0:0,1:1,2:2,3:3,4:5,5:7,6:8,7:9}
for i in range(len(inputlist)-1):
	temp=[0]*10
	octnpower(inputlist[i])
	for i in range(len(temp)):
		temp[i]=octdictionary[temp[i]]
	temp.reverse()
	for j in range(len(temp)):
		index=j
		if(temp[j]!=0):break
	temp=temp[index:]
	ansstr=""
	for j in range(len(temp)):
		ansstr+=str(temp[i])
	print ansstr