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 <cstdio>

void ToOctalNumber(int n){
	if(n){
		ToOctalNumber(n >> 3);
		printf("%d",(n&7)<4?n&7:(n&7)==4?5:(n&7)+2);
	}
}

int main(){
	int n;
	while(scanf("%d",&n),n){
		ToOctalNumber(n);
		puts("");
	}
}

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

using namespace std;

int main(){
  while(1){
    int v;
    scanf("%d", &v);
    if(v==0) break;

    int i;
    list<int> data;
    for(i=0;v;i++){
      switch(v%8){
      case 0:
      case 1:
      case 2:
      case 3:
        data.push_back(v%8);
        break;
      case 4:
        data.push_back((v%8)+1);
        break;
      case 5:
      case 6:
      case 7:
        data.push_back((v%8)+2);
        break;
      }
      v /= 8;
    }

    v = data.size();
    for(i=0;i<v;i++){
      printf("%d", data.back());
      data.pop_back();
    }
    puts("");
  }
}

C++: // #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;

#define MP make_pair
#define fastIO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
int INPUT_INT() { int d; cin >> d; return d; } // 入力をpush_back(d)やarray[d]に使う時に1行で書ける

// ------------------- include, typedef, define END. -------------------

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

void solve(int n){
	if (n >= 8)
		solve(n / 8);
	cout << table[n % 8];
}

int main(){
	fastIO;
	// 文字01235789を使う8進数として考える.
	// 参考リンク4つ
	// http://d.hatena.ne.jp/nanikaka/20111120/1321748152
	// http://refiute.hatenablog.com/entry/20110907/1315381210
	// http://program.pinemz.net/article/168162542.html
	// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=180052

	// 1. 数値 (= n) を 8 で割った余りをその位の値とする.
	// 2. n を 8 で割り, その答えを n として 1 に戻る.
	// (8進数に変換しているだけ. 8→5とかでもいけるはず.)

	// これは下位桁から求めている.再帰にして上位桁から出力する.

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

C++: #import<cstdio>
int t[]={,1,2,3,5,7,8,9,};void s(int n){if(n>7)s(n/8);printf("%d",t[n%8]);}main(){for(int a;scanf("%d",&a),a;puts(""))s(a);}

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

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

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    vector<int> ans;
    while (n > 0) {
      ans.push_back(d2o[n%8]);
      n /= 8;
    }

    for (int i = ans.size()-1; i >= 0; --i)
      cout << ans[i];
    cout << endl;
  }
  return 0;
}

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

int main() {

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

  while( true ) {

    long long int input;

    cin >> input;

    if ( input == 0 ) break;

    long long int ans = 0;

    for( long long int i = 1; input > 0; i *= 10 ) {

      ans += heya[ input % 8 ] * i;

      input /= 8;

    }

    cout << ans << endl;

  }

  return 0;

}

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

signed main(){
	int chg[] = {0,1,2,3,5,7,8,9};
	int n;
	while(cin >> n,n){
		int nn = n,to = 0,tmp = 1,keta = 0;
		while(nn){
			to += (nn % 8) * tmp;
			tmp *= 10;
			nn /= 8;
			keta++;
		}
		tmp = 1;
		for(int i = 0;i < keta;i++){
			int pos = (to / tmp) % 10;
			to += (chg[pos] - pos) * tmp;
			tmp *= 10;
		}
		cout << to << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cctype>
#include <utility>
#include <stack>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m?-n:n;}
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	static const int tr[] = {0, 1, 2, 3, 5, 7, 8, 9};
	stack<int> s;
	for (int n; (n = in());) {
		for (; n; n /= 8)
			s.push(tr[n % 8]);
		for (; !s.empty(); s.pop())
			out(s.top());
		outl();
	}
}

C++: #include <iostream>

using namespace std;


int main(){
    long ans=0;
    int c=0;
    int n;
    while(cin>>n){
        ans+=n%8*pow(10,c);
        n/=8;
        if(n==0)break;
        c++;
    }
    for(int i=0;i<=c;i++){
        int temp=((long)(ans/pow(10,i))%10);
        if(temp==4)ans+=pow(10,i);
        if(temp>=5)ans+=2*pow(10,i);
    }
    cout<<ans<<endl;

    return 0;
}

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

int main()
{
	int n,x;
	long long a;
	while(cin >> n, n)
	{
		a=0;
		for(int i=30; i>=0; i-=3)
		{
			a *= 10;
			x = (int)((n>>i)&7);
			x += x/4 + x/5;
			a += x;
		}
		cout << a << endl;
	}
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	ll n;
	ll m;
	cin >> n;
	if(n==0) break;
	m = 0;
	int x = 1;
	while(n>0){
	    int mo = n % 8;
	    if(mo >= 5){
		m += (2 + (n % 8) )*x ;
	    }else if(mo >= 4){
		m += (1 + (n % 8))*x ;
	    }else{
		m += (n % 8)*x ;
	    }
	    x *= 10;
	    n /= 8;
	}
	cout << m << endl;
    }
    return 0;
}

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