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 <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

//typedef __int64 ll;
typedef long long ll;
ll n;

int main(){
	while(cin>>n){
		if(!n)return 0;
		ll m=n,d=1,p;
		while(m>7){m/=8;d++;}
		for(int i=d-1;i>=0;i--){
			p=(n/(int)(pow(8,i)+0.1))%8;
			if(p<4)cout<<p;
			else if(p<5)cout<<p+1;
			else cout<<p+2;
		}
		cout<<endl;
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

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

// 10?????°x???b?????°?????????
vector<ll> decimalConvert(ll x, ll b, int keta = 64) {
	vector<ll> res;
	while (x) {
		res.push_back(x % b);
		x /= b;
	}
	while (res.size() < keta) res.push_back(0);
	reverse(ALL(res));
	
	return res;
}


int main() {
	int n;
	while (cin >> n, n) {
		vector<ll> v = decimalConvert(n, 8, 20);
		
		string ans = "";
		REP(i, v.size()) ans += conv[v[i]] + '0';
		
		int z = 0;
		while (z < ans.size() && ans[z] == '0') z++;
		if (z == ans.size()) ans = "0";
		else ans = ans.substr(z);
		
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main( void )
{
	long long n;
	while ( cin >> n && n != 0 )
	{
		ostringstream os;
		os << oct << n;
		string n_str = os.str();
		for ( string::iterator it = n_str.begin(); it != n_str.end(); it++ )
		{
			char c = *it;
			if ( c >= '4' ) (*it)++;
			if ( c >= '5' ) (*it)++;
		}
		istringstream is( n_str );
		is >> n;
		cout << n << endl;
	}

	return 0;
}

C++: #include <stdio.h>
#include <string.h>

int main(void)
{
	int old;
	int i, len;
	char ne[100];
	while (1){
		scanf("%d", &old);
		
		if (old == 0){
			break;
		}
		
		i = 0;
		while (old != 0){
			ne[i] = old % 8 + '0';
			old /= 8;
			i++;
		}
		ne[i] = '\0';
		len = strlen(ne) - 1;
	
		for (i = 0; i <= len; i++){
			if ('5' <= ne[len  - i]){
				ne[len - i] += 2;
			}
			else if ('4' <= ne[len - i]){
				ne[len - i]++;
			}
			
			printf("%c", ne[len - i]);
		}
		puts("");
	}
	return (0);
}

C++: #include <iostream>
#include <algorithm>
//#include <fstream>

using namespace std;

string dec2oct (int n )
{
	string res = "";

	while (n > 0 ){
		res += n % 8 + '0';
		n /= 8;
	} // end while
	
	reverse (res.begin(), res.end() );

	return res;
}

string hostpial_number (string s )
{
	int len = s.length();
	string res = "";
	int i;

	for (i = 0; i < len; ++i){
		if (s[i] != '4' && s[i] != '5' && s[i] != '6' && s[i] != '7'){
			res += s[i];
		}else if (s[i] == '4'){
			res += '5';
		}else if (s[i] == '5'){
			res += '7';
		}else if (s[i] == '6'){
			res += '8';
		}else if (s[i] == '7'){
			res += '9';
		} // end if
	} // end for

	return res;
}


int main()
{
//	cut here before submit 
//	freopen ("testcase.hospitalnumber", "r", stdin );
	int n;

	while (cin >> n && n ){
		string oct = dec2oct (n );
		string res = hostpial_number (oct );
		cout << res << endl;
	} // end loop
		
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int i;
  char s[10];
  while(cin>>i,i){
    sprintf(s,"%o",i);
    for(i=0;s[i]!='\0';i++){
      if(s[i]>='4')s[i]++;
      if(s[i]>='6')s[i]++;
}
    printf("%s\n",s);
}
}

C++: #include <iostream>
#include <string>
#define int long long
using namespace std;
signed main() {
	int a[10];
	a[0] = 0; a[1] = 1; a[2] = 2; a[3] = 3; a[4] = 5; a[5] = 7; a[6] = 8; a[7] = 9;
	int n;
	while (cin >> n, n) {
		string ans;
		int m = n;
		while (m > 0) {
			ans = (char)(a[m % 8] + '0') + ans;
			m /= 8;
		}
		cout << ans << endl;
	}
}

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

int main() {
	long long ans;
	int i,k,n,o[10];
	for (i=1,o[0]=1;i<10;i++) o[i]=o[i-1]*8;
	while(cin >> n && n>0) {
	ans=0;	
	for (i=9;i>=0;i--) {
		if (n>=o[i]) { k=n / o[i]; n=n % o[i];
		               if (k==4) k=5; else  if (k>4) k+=2;
		               ans+=k;
		                }
		if (i>0) ans=ans*10;
		}
	cout << ans << endl; 		   
}
	return 0;
}

C++: #include <iostream>
using namespace std;
int  main(){
  char s[]={'0','1','2','3','5','7','8','9'};
  long long int n;
  for(;cin>>n,n;)
    {
      string a="";
      for(;n>0;n/=8)
	a=s[n%8]+a;
      cout<<a<<endl;
    }
}

C++: #include<iostream>

int n;
int pw[10] = {1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000};

void solve(){
	__int64 ans = 0;
	int tmp = n;
	for(int i=0; i<10; i++){
		int temp = tmp%8;
		if(temp==4)
			temp++;
		else if(temp > 4)
			temp+=2;
		ans += temp*pw[i];
		tmp = tmp/8;
		if(tmp == 0)
			break;
	}
	std::cout << ans << std::endl;
}

int main(){
	while(true){
		std::cin >> n;
		if(!n)
			return 0;
		solve();
	}
}

C++: #include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>

#define REP(i,n) for(int i=0; i<n; i++)
#define FOR(i,a,b) for(int i=a; i<=b; i++)

using namespace std;

int main(void) {
	int c[8] = { 0,1,2,3,5,7,8,9 };
	int n;
	vector<int> v;
	while (cin >> n && n > 0) {
		v.clear();
		while (n > 0) {
			v.push_back(c[n % 8]);
			n /= 8;
		}
		for (int i = v.size() - 1; i >= 0; i--) {
			cout << v[i];
		}
		cout << endl;
	}
	
				  
	return 0;
}

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

int main() {
	int n;
	// your code goes here
	while(cin>>n){
	if (n==0) break;	
	int a[11]={0};
	int keta=-1;
	for(int u=1;u<11;u++){
		a[u]=n%8;
		n=(n-a[u])/8;
		if(keta == -1 && n==0) keta=u;
		
	}
	
	for(int y=keta;y>0;y--){
		if(a[y]==0) cout<<"0";
		if(a[y]==1) cout<<"1";
		if(a[y]==2) cout<<"2";
		if(a[y]==3) cout<<"3";
		if(a[y]==4) cout<<"5";
		if(a[y]==5) cout<<"7";
		if(a[y]==6) cout<<"8";
		if(a[y]==7) cout<<"9";
		
	}
	cout<<endl;
	
	
	
	
	}
	

}

C++: #include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

typedef long long ll;


int fourOrSixPlace(ll num){
	int idx=-1;
	int cnt=0;
	while(num>0){
		if(num%10==6||num%10==4){
			idx=cnt;
		}
		num/=10;
		cnt++;
	}
	return idx;
}

int main(){

	//int cc=0;
	//for(ll i = 1; i <= 10000; i++){
	//	int ret=fourOrSixPlace(i);
	//	if(ret!=-1)
	//		cc++;
	//}
	//cout<<cc<<endl;
	ll n;
	while(cin>>n&&n!=0){
		ll cnum=0;
		ll cnt=0;
		while(1){
			cnum+=10000;
			if(cnum>n)
				break;
			int ret=fourOrSixPlace(cnum);
			if(ret==-1){
				n+=5904;
			}
			else{
				n+=5904;
				cnum+=(ll)(pow(10.0,ret)+0.1);
				n+=(ll)(pow(10.0,ret)+0.1);
			}
		}
		if(cnum==n){
			cout<<n<<endl;
		}
		else{
			cnum-=10000;
			cnum++;
			for(ll i = cnum; i <= n; i++){
				int ret=fourOrSixPlace(i);
				if(ret!=-1){
					if(ret==0){
						n++;
					}
					else{
						n+=(ll)pow(10.0,ret);
						i+=(ll)pow(10.0,ret);
					}
				}
			}
		}
		cout<<n<<endl;
	}

	return 0;
}