Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	table := []int{0, 1, 2, 3, 5, 7, 8, 9}
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		out := make([]int, 10)
		now := 0
		for n > 0 {
			out[now] = table[n%8]
			now++
			n /= 8
		}
		tmp := make([]string, 0)
		for i := now - 1; i >= 0; i-- {
			tmp = append(tmp, strconv.Itoa(out[i]))
		}
		fmt.Println(strings.Join(tmp, ""))
	}
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) 
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }

int n;

vector<int> tovec(long long a, int n) {
    vector<int> res;
    while (true) {
        if (a < n) {res.push_back(a); break;}
        else {res.push_back((int)(a%n)); a /= n;}
    }
    return res;
}

int base[8] = {0, 1, 2, 3, 5, 7, 8, 9};

int main() {
    while (cin >> n) {
        if (n == 0) break;
        vint vec = tovec(n, 8);
        reverse(ALL(vec));
        long long res = 0;
        for (int i = 0; i < vec.size(); ++i) {
            res += base[vec[i]];
            if (i != vec.size()-1) res *= 10;
        }
        cout << res << endl;
    }
    return 0;
}

C++: #include <cstdio>
int map[10];
char buf[32];
int main()
{
    for (int i = 0; i < 8; ++i) {
        if (i < 4) map[i] = i;
        else if (i == 4) map[i] = 5;
        else map[i] = i + 2;
    }
    int n;
    while (scanf("%d", &n), n) {
        sprintf(buf, "%o", n);
        for (char* c = buf; *c != '\0'; c++)
            putchar((char)(map[*c - '0'] + '0'));
        puts("");
    }
    return 0;
}

C++: // AOJ 0208
// Room Numbers of Hospital (a@Ì®Ô)

#include <cstdio>

using namespace std;

const int table[] = { 0, 1, 2, 3, 5, 7, 8, 9 };

void solve(int n){
    
    if(n >= 8){
        solve(n / 8);
    }
    
    printf("%d", table[n % 8]);
}

int main(){
    int n;
    
    while(scanf("%d", &n), n > 0){
        solve(n);
        printf("\n");
    }
    
    return 0;
}

C++: #include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef long long LL;
typedef istringstream ISS;
typedef ostringstream OSS;

char toChar( int n ) {
    return n + '0';
}

string toSeven( LL n ) {
    string s;
    while ( n >= 8 ) {
        s += toChar( n % 8 );
        n /= 8;
    }
    s += toChar( n );
    reverse( s.begin(), s.end() );
    return s;
}

LL toNewNumber( string s ) {
    char T[8] = { '0', '1', '2', '3', '5', '7', '8', '9' };
    string t = s;
    int n = s.size();
    for ( int i = 0; i < n; ++ i ) {
        s[i] = T[ s[i] - '0' ];
    }
    ISS iss1( s );
    LL res;
    iss1 >> res;
    return res;
}

LL solve( LL n ) {
    return toNewNumber( toSeven( n ) );
}

int main() {
    LL n;
    while ( cin >> n && n ) {
        cout << solve( n ) << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

/*
1 2 3 5 7 8 9 10 11 12 13 15 17 18 19 new
1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 
*/

string changeStr(long long n){
    long long copy = n;
    int len = -1;
    while(copy != 0){
        len++;
        copy/=10;
    }

    string str;
    long long K = 1;
    rep(i,len) K*=10;
    rep(i,len + 1){
        if(n / K == 0) str+= '0';
        else str+= ('0' + n / K);
        n%=K; K/=10;
    }
    return str;
}

long long newRoomNumber(long long o){ //old number, new number
    long long n = 0, K = 1;
    while(o != 0){
        n+= (o % 8) * K;
        o/= 8;
        K*=10;
    }
    return n;
}

string deleteFourAndSix(string n){
    rep(i,n.size()){
        if(n[i] == '4') n[i] = '5';
        else if(n[i] == '5') n[i] = '7';
        else if(n[i] == '6') n[i] = '8';
        else if(n[i] == '7') n[i] = '9';
    }
    return n;
}

int main(){
    long long n;
    while(cin >> n, n){
        cout << deleteFourAndSix(changeStr(newRoomNumber(n))) << endl;
    }
}

C++: #include<stdio.h>
int main() {
long long a,b,c;
int x[8]={0,1,2,3,5,7,8,9};
while(scanf("%d",&a),a) {
c=1;b=0;
while(a) {
b+=x[a&7]*c;
c*=10;a=a>>3;
}
printf("%lld\n",b);
}
}

C++: #include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	char conv[8]={'0','1','2','3','5','7','8','9'};
	while(true){
		int X=in();
		if(!X) break;
		vector<int> V;
		while(X){
			V.push_back(X%8);
			X/=8;
		}
		reverse(ALL(V));
		for(auto& x:V) cout<<conv[x];
		out();
	}

	return 0;
}

C++: #include <iostream>
#include <cmath>
using namespace std;

int main()
{
    while(1)
    {
        long long n;
        cin>>n;if(!n)return 0;
        long long a=n;
        int k=-1;
        for(;a>0;++k){
            a/=8;
        }
        for(;k>=0;--k){
            int ans=n/pow(8,k);
            if(ans==4)cout<<5;
            else if(ans>4)cout<<ans+2;
            else cout<<ans;
            n=n%(long long)pow(8,k);
        }
        cout<<endl;
    }
    return 0;
}

C++: #include <cstdio>
using namespace std;
const int table[] = { 0, 1, 2, 3, 5, 7, 8, 9 };
void solve(int n){
   
    if(n >= 8){
        solve(n / 8);
    }
    
    printf("%d", table[n % 8]);
}

int main(){
    int n;
    
    while(scanf("%d", &n), n > 0){
        solve(n);
        printf("\n");
    }
    
    return 0;
}