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<bits/stdc++.h>
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 <stdio.h>
 
int main(void) {
	int i;
char ans[10];
while(scanf("%d",&i),i){
sprintf(ans,"%o",i);
for(i=0;i<10;i++){
if(ans[i]==0) break;

if(ans[i]>=4) ans[i]++;
if(ans[i]>=6) ans[i]++;

}
printf("%s\n",ans);
}
	return 0;
}

C++: #include <iostream>

using namespace std;

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

void dfs(long long n) 
{
    if (n >= 8)
        dfs(n / 8);
    cout << ch[n % 8];
}

int main()
{
    long long n;

    while (cin >> n, n) {
        dfs(n);
        cout << endl;
    }

    return 0;
}

C++:                                                             
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii;
typedef long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()

int main(void){
  int no[] = {0,1,2,3,5,7,8,9};
  int num;
  while(cin>>num,num){
    vector<int> inp;
    while(num>0){
      inp.push_back(num%8);
      num/=8;
    }

    reverse(all(inp));

    rep(i,inp.size()){

      cout<<no[inp[i]];
    }
    cout<<endl;
  }
}

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

string tenToEight(int t) {
  string res = "";
  while(t >= 8) {
    res += (char)(t%8+'0');
    t /= 8;
  }
  res += (char)(t+'0');
  reverse(res.begin(),res.end());
  return res;
}

int main() {
  int n;
  string conv = "01235789";
  while(cin >> n && n) {
    string eight = tenToEight(n);
    for(int i = 0; i < eight.size(); ++i) cout << conv[eight[i]-'0'];
    cout << endl;
  }
  return 0;
}

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

long long int solve(long long int N) {
    string s = to_string(N);
    int len = s.length();
    
    long long int dp[15][2] = {};
    dp[0][0] = 1;
    for(int i=0; i<len; i++) {
        for(int j=0; j<2; j++) {
            int lim = j ? 9 : s[i] - '0';
            for(int x=0; x<lim+1; x++) {
                if(x == 4 || x == 6) continue;
                dp[i+1][j || x < lim] += dp[i][j];
            }
        }
    }
    
    long long int ret =  dp[len][0] + dp[len][1] - 1;
    return ret;
}


int main(void){
    // Your code here!
    int N;

    while(cin >> N, N) {
        long long int ub = 1LL << 40, lb = 0;
        while(ub - lb > 1) {
            long long int mid = (ub + lb) / 2;
            long long int val = solve(mid);
            
            if(val >= N) ub = mid;
            else lb = mid;
        }
        cout << ub << endl;
    }
    return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

void f(int n){
	if(n>=8)f(n/8);
	n%=8;
	if(n<4)cout<<n;
	else if(n==4)cout<<5;
	else cout<<n+2;
}

int main() {
	int n;
	while(n=in()){
		f(n);
		cout<<endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

typedef long long ll;

ll count_rooms_lesseq_than(ll newRoomNo)
{
	int t[10], d;
	for (d = 0; newRoomNo; ++d, newRoomNo /= 10)
		t[d] = newRoomNo % 10;
	for (int i = d-1; i > 0; --i)
	{
		if (t[i] == 4 || t[i] == 6)
		{
			--t[i];
			for (int j = 0; j < i; ++j)
				t[j] = 9;
			break;
		}
	}

	ll res = 0;
	for (int i = 0; i < d; ++i)
	{
		ll a = 1;
		for (int j = 0; j < i; ++j)
			a *= 8;
		res += (t[i] - (t[i] >= 6 ? 2 : t[i] >= 4 ? 1 : 0)) * a;
	}
	return res;
}
int main()
{
	int n;
	while (scanf("%d", &n), n)
	{
		ll l, u;
		l = 1;
		u = n * 10LL;
		while (l < u)
		{
			ll m = (l + u) / 2;
			ll t = count_rooms_lesseq_than(m);
			if (t < n)
				l = m + 1;
			else
				u = m;
		}
		printf("%lld\n", l);
	}

	return 0;
}

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

int main() {
	unsigned n;
	while (cin >> n, n) {
		int b=1;
		long long m=0;
		while (n) {
			m += b*(n%8);
			n /= 8;
			b *= 10;
		}

		stringstream ss;
		string s;
		ss << m;
		ss >> s;
		ss.str("");
		ss.clear(stringstream::goodbit);
		for (int i=0; i<s.size(); i++) {
			if (s[i]=='4') s[i]='5';
			else if (s[i]=='5') s[i]='7';
			else if (s[i]=='6') s[i]='8';
			else if (s[i]=='7') s[i]='9';
		}
		ss << s;
		ss >> m;
		cout << m << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int data[]={0, 1, 2, 3, 5, 7, 8, 9};
void solve(int);
main(){
  int n;
  while(1){
    cin >> n;
    if(n==0) break;
    solve(n);
    cout << endl;
  }
  return 0;
}

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

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

using namespace std;

typedef long long ll;

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

ll hatisin(ll a) {
  ll res = 0;
  ll i = 1;
  int t = 0;
  while(a > 0) {
    t = a % 8;
    res += t * i;
    a /= 8;
    i *= 10;
  }
  return res;
}

ll fukkatu(ll b) {
  ll res = 0;
  ll i = 1;
  int t = 0;
  while(b > 0) {
    t = b % 10;
    res += V[t] * i;
    i *= 10;
    b /= 10;
  }
  return res;
}

int main() {
  ll res;
  while(cin >> res) {
    cout << fukkatu(hatisin(res)) << endl;
  }
  
  return 0;
}

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

int main() {
    int n, m;
    string number;

    while (cin >> n, n) {
        number = "";
        while (n > 0) {
            m = n % 8;
            if (m > 4) {
                m += 2;
            }
            else if (m == 4) {
                m += 1;
            }
            number = " " + number;
            number[0] = '0' + m;
            n /= 8;
        }
        cout << number << endl;
    }
    return 0;
}

C++: #include<iostream>
int main(){
	while(1){
		int a;
		std::cin>>a;
		if(a==0)break;
		int g=0;
		for(int i=0;i<a;i++){
			g++;
			int n=10;
			for(int i=1;i<10;i++){
				if(g%n==4||g%n==6||g/n==4||g/n==6)g++;
				n*=10;
			}
		}
		std::cout<<g<<std::endl;
	}
		return 0;
	}

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

using namespace std;

int main(void)
{
	// itoa
	int n;
	while (cin >> n, n){
		char s[20];
		_itoa(n, s, 8);
		
		string str = s;
		for (int i = 0; i < str.length(); i++){
			if ('4' <= str[i]) str[i]++;
			if ('6' <= str[i]) str[i]++;
		}
		cout << str << endl;
	}
	
	return 0;
}