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<vector>
#include<algorithm>

using namespace std;

int num;
int data[8] = {0,1,2,3,5,7,8,9};
vector<int> make(){
  vector<int> out;
  while(num){
    out.push_back(num%8);
    num/=8;
  }
  reverse(out.begin(),out.end());
  return out;
}

int main(){
  while(cin >> num && num){
    vector<int> V = make();
    for(int i = 0; i < V.size(); i++) cout << data[V[i]];
    cout << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>

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

int main(){
	int n;
	while (std::cin >> n, n){
		std::string v;

		while (n != 0){
			char a;
			a = n % 8 + '0';
			v += a;
			n /= 8;
		}
		for (int i = v.size() - 1; i >= 0; i--){
			int j = v[i] - '0';
			v[i] = q[j] + '0';
			std::cout << v[i];
		}
		std::cout << std::endl;
	}
	return 0;
}

C++: #include<iostream>
#include<sstream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cfloat>
#include<functional>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<bitset>
#include<list>
#include<numeric>
#include<complex>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<long long, long long> ll_ll;
typedef pair<double, double> d_d;
typedef vector<int> Vint;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define rep2d(i, j, n) for(i = 0;i < n;++i)for(j = i + 1;j < n;++j)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << x << "\n"
#define pri2(x, y) cout << x << " " << y << "\n"
#define pri3(x, y, z) cout << x << " " << y << " " << z << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << x << "\n"
#define debug2(x, y) cout << " --- " << x << " " << y << "\n"
#define debug3(x, y, z) cout << " --- " << x << " " << y << " " << z << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

int res[20] = {0};
signed main(void){
  int i, j, k;
  for(int testcase = 0;testcase >= 0;testcase++){
    int(n); if(!n)break;
    rep(i, 20)res[i] = -1;
    int head = 0;

    for(;n > 0;){
      res[head++] = n % 8;
      if(res[head - 1] >= 4)res[head - 1]++;
      if(res[head - 1] >= 6)res[head - 1]++;
      n /= 8;
    }
    per(i, head)cout << res[i];
    kara;



//*/

//*/ break;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main(void){
  
  int num[] = {0,1,2,3,5,7,8,9};
  int n;
  long long a = 0;
  long long b = 1;
  
  while( cin >> n , n ){
    
    a = 0;
    b = 1;
    while(n){
      a += num[n % 8] * b;
      b *= 10;
      n /= 8;
    }
    cout << a << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>

using namespace std;

int main(void){
	//01234567
	//01235789
	int n;
	while(cin >> n && n){
		string str = "";
		
		while(n > 0){
			str += n % 8 + '0';
			n /= 8;
		}
		for(int i=0;i<str.size();i++){
			if(str[str.size() - 1 - i] <= '3' ){
				cout << str[str.size() - 1 - i];
			}else if(str[str.size() - 1 - i] >=  '5'){
				cout << (char)(str[str.size() - 1 - i]+2);
			}else{
				cout << (char)(str[str.size() - 1 - i]+1);
			}
		}
		cout << endl;
	}
}

C++: #include <iostream>
#include <string>

using namespace std;

string convert(int n){ 
        string s = ""; 
        while(n){
                s += n%8 + '0';
                n /= 8;
        }   
        string _s = ""; 
        for(int i = s.size()-1; i >= 0; i--){
                char c = s[i];
                if(c >= '4') c++;
                if(c >= '6') c++;
                _s += c;
        }   
        return _s; 
}

int main(){
        int n;
        cin >> n;
        while(n){
                cout << convert(n) << endl;
                cin >> n;
        }   
}

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

void solve(int n);

int main(){
	while(1){
		int n;
		cin >> n;
		if(n==0) break;
		solve(n);
		cout << endl;
	}
}


void solve(int n){
	if(n == 0) return;
	solve(n/8);
	int a = n % 8;
	cout << (a==4?5:(a>4?a+2:a));
}

C++: #include <iostream>
#include <cmath>

using namespace std;

int main(){
  char newnum[8] = {0,1,2,3,5,7,8,9};
  long input_num,output_num;
  int count_num;
  while(cin >> input_num && input_num != 0){
    output_num = 0;
    count_num = 0;
    while(input_num != 0){
      output_num += newnum[input_num % 8] * pow(10,(double)count_num);
      input_num /= 8;
      //      cout << output_num << " " ;
      count_num++;
    }
    cout << output_num;
    cout << endl;
  }

}

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

int main(){
	long long n;
	while(cin >> n && n){
		char s[100] = {};
		char table[] = "01235789";
		sprintf(s,"%o",n);
		int i = 0;
		while(s[i]){
			putchar(table[s[i]-'0']);
			i++;
		}
		
		putchar('\n');
	}
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int NUM = 1000000000;
const int L = 11;

string translation(int N){
  stringstream ss;
  while(N > 0){
    ss <<N % 8;
    N /= 8;
  }
  string s = ss.str();
  REVERSE(s);
  return s;
}

int main() {
  char n[9] = {'0', '1', '2', '3', '5', '7', '8', '9'};
  int N;
  while(cin >>N && N){
    string s = translation(N);
    REP(i, s.length()) cout <<n[s[i] - '0'];
    cout <<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
	int room;
    char hospital[11];
	
    while(cin >> room, room)
    {
        sprintf(hospital, "%o", room);
    	
    	for(int i = 0; i < 11; i++)
    	{
    		if(hospital[i] == '4')
    		{
    			hospital[i] = '5';
    		}
    		else if(hospital[i] > '4')
    		{
    			hospital[i] += 2;
    		}
    	}
    	cout << hospital << endl;
    }
    
    return 0;
}

C++: #include<iostream>
#include<sstream>
#include<algorithm>

using namespace std;

const string s = "01235789";

int main(){
  int n;
  while(cin >> n, n){
    stringstream ss;
    while(n){
      ss << s[n % 8];
      n /= 8;
    }
    string ans = ss.str();
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
  }
  return 0;
}