Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		h := make([]int, 5)
		h[0], _ = strconv.Atoi(scanner.Text())
		if h[0] == 0 {
			break
		}
		for i := 1; i <= 4; i++ {
			scanner.Scan()
			h[i], _ = strconv.Atoi(scanner.Text())
		}
		tbl := make([]bool, 3)
		aiko := false
		for _, v := range h {
			tbl[v-1] = true
		}
		if tbl[0] && tbl[1] && tbl[2] { // 全ての手があるあいこ
			aiko = true
		}
		if h[0] == h[1] && h[1] == h[2] && h[2] == h[3] && h[3] == h[4] {
			aiko = true
		}
		if aiko {
			fmt.Printf("3\n3\n3\n3\n3\n")
		} else {
			win := 0
			if !tbl[0] {
				win = 2
			}
			if !tbl[1] {
				win = 3
			}
			if !tbl[2] {
				win = 1
			}
			for i := 0; i < 5; i++ {
				if h[i] == win {
					fmt.Println(1)
				} else {
					fmt.Println(2)
				}
			}
		}
	}
}

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

int searchWin(int a, int b);

int main(){
    int a[5];
    while(cin >>a[0]){
        vector<int> vec(4, 0);
        if(a[0] == 0) break;
        vec[a[0]]++;
        bool aiko = false;
        for(int i = 1; i < 5; i++){
            cin >>a[i];
            vec[a[i]]++;
        }

        if(vec[1] != 0 && vec[2] != 0 && vec[3] != 0) aiko = true;
        if((vec[1] == 0 && vec[2] == 0) || (vec[2] == 0 && vec[3] == 0) || (vec[3] == 0 && vec[1] == 0)) aiko = true;

        if(aiko){
            for(int i = 0; i < 5; i++) cout <<3 <<endl;
        } else{
            vector<int> v;
            for(int i = 1; i <= 3; i++){
                if(vec[i] != 0) v.push_back(i);
            }
            int win = searchWin(v[0], v[1]);
            for(int i = 0; i < 5; i++){
                if(win == a[i]) cout <<1 <<endl;
                else cout <<2 <<endl;
            }
        }
    }
    return 0;
}

int searchWin(int a, int b){
    if(a == 1){
        if(b == 2) return a;
        else return b;
    } else if(a == 2){
        if(b == 1) return b;
        else return a;
    } else{
        if(b == 1) return a;
        else return b;
    }
}

C++: #include<stdio.h>

int main(void){
  int a[5],i;
  while(scanf("%d",&a[0])){
    int used[3];
    used[0]=used[1]=used[2]=0;
    for(i=1;i<5;i++)scanf("%d",&a[i]),used[a[i]-1]=1;
    if(used[0]&&used[1]&&used[2]){
      for(i=0;i<5;i++)printf("3\n");
      continue;
    }
    for(i=0;i<5;i++){
      switch(a[i]){
      case 1:
	if(used[1])printf("1\n");
	else printf("2\n");
	break;
      case 2:
	if(used[2])printf("1\n");
	else printf("2\n");
	break;
      case 3:
	if(used[0])printf("1\n");
	else printf("2\n");
	break;
      }
    }
  }
}

C++: #include <iostream>

using namespace std;

int main(){
	int hand[5];
	bool handbe[3];
	bool isdraw;
	while (1){
		isdraw = false;
		handbe[0] = false;
		handbe[1] = false;
		handbe[2] = false;

		cin >> hand[0];
		if (hand[0] == 0)break;
		handbe[hand[0]-1] = true;
		for (int i = 1; i < 5; ++i){
			cin >> hand[i];
			handbe[hand[i]-1] = true;
		}

		if (handbe[0]){//あいこ判定
			if (handbe[1] == handbe[2])isdraw = true;
		} else{
			if (handbe[1] != handbe[2])isdraw = true;
		}

		if (isdraw){
			for (int i = 0; i < 5; ++i){
				cout << "3" << endl;
			}
			continue;
		}

		for (int j = 0; j < 3; ++j){
			if (handbe[j] && handbe[(j+1)%3]){
				for (int i = 0; i < 5; ++i){
					cout << (hand[i] == ((j+1)%3) ? 1 : 2) << endl;
				}
			}
		}
	}

	return 0;
}

C++: #include<iostream> 
main(){for(;;){int d[5]={},s=0,i=0;for(;i<5;i++){int h;std::cin>>h;if(!h)return 0;s|=d[i]=1<<(h-1);}for(i=0;i<5;i++){std::cout<<(s==7|s==d[i]?3:((s^d[i])==d[i]*2|(s^d[i])==d[i]/4?1:2))<<"\n";}}}

C++: #include<iostream>
using namespace std;
int main(){
long x[5],h[4],i,j;
while(cin>>x[0]){
if(x[0]==0)break;
for(i=1;i<=3;i++)h[i]=0;
h[x[0]]++;
for(i=1;i<5;i++){cin>>x[i];h[x[i]]++;}
for(j=0,i=1;i<=3;i++)if(h[i]==0)j++;
if(j==2||j==0){
for(i=0;i<5;i++)cout<<"3"<<endl;
}else{
for(i=1;i<=3;i++)if(h[i]==0)break;
if(i==1){
for(i=0;i<5;i++)cout<<x[i]-1<<endl;
}else if(i==2){
for(i=0;i<5;i++)cout<<(x[i]+1)%3<<endl;
}else if(i==3){
for(i=0;i<5;i++)cout<<x[i]<<endl;
}
}
}
return 0;
}

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

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

int main() {
	ios::sync_with_stdio(false);
	
	int a[5], c[3];
	
	while(1) {
		cin >> a[0];
		if(!a[0])break;
		repi(i, 1, 5) cin >> a[i];
		
		rep(i, 3) c[i] = 0;
		rep(i, 5) c[a[i]-1]++;
		if( (c[0]>0&&c[1]>0&&c[2]>0) || (c[0]==5) || (c[1]==5) || (c[2]==5) ) {
			rep(i, 5)cout << 3 << endl;
		}else if(c[0]==0) {
			rep(i, 5)cout << (a[i]==2?1:2) << endl;
		}else if(c[1]==0) {
			rep(i, 5)cout << (a[i]==3?1:2) << endl;
		}else if(c[2]==0) {
			rep(i, 5)cout << (a[i]==1?1:2) << endl;
		}
	}
	
	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
	int human[5];
	while (cin >> human[0], human[0]) {
		for (int i = 1; i < 5; ++i)
			cin >> human[i];
		
		int hands[3] = {0};
		for (int i = 0; i < 5; ++i)
			hands[human[i]-1] = 1;
		
		int k = 0, no = 0;
		for (int i = 0; i < 3; ++i)
			if (hands[i]) ++k;
			else no = i + 1;
		
		if (k == 2) {
			no = (no + 1) % 3 + 1;
			for (int i = 0; i < 5; ++i)
				if (human[i] == no) cout << "2" << endl;
				else cout << "1" << endl;
		}
		else
			for (int i = 0; i < 5; ++i)
				cout << "3" << endl;
	}
}

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

int main(){
	while(1){
		int n, hand[3] = {0};
		cin >> n;
		if(n == 0) break;
		hand[n - 1] = 1;
		for(int i = 1;i < 5;i++){
			int h;
			cin >> h;
			hand[h - 1] = 1 << i;
		}
		for(int i = 0;i < 5;i++){
			int h = 0;
			while(!(hand[h] & 1 << i)) h++;
			int ans = 0;
			if(hand[(h + 1) % 3]) ans += 1;
			if(hand[(3 + h - 1) % 3]) ans += 2;
			if(ans == 0) ans = 3;
			cout << ans << endl;
		}
	}
		
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(void){

  int j[5];
  bool R,S,P;


  while(cin >> j[0], j[0]){
    for( int i = 1 ; i < 5 ; i++ ){
      cin >> j[i];
    }
    R = S = P = false;
    for( int i = 0 ; i < 5 ; i++ ){
      if(j[i] == 1 ) R = true;
      if(j[i] == 2 ) S = true;
      if(j[i] == 3 ) P = true;
    }

    if( R && S && P )
      for( int i = 0 ; i < 5 ; i++ )
	cout << "3" << endl;
    else if( R && S && !P ) // パーなし
      for( int i = 0 ; i < 5 ; i++ ){
	switch(j[i]){
	case 1:
	  cout << "1" << endl;
	  break;
	case 2:
	  cout << "2" << endl;
	  break;
	}
      }
    else if( R && !S && P ) // チョキなし
      for( int i = 0 ; i < 5 ; i++ ){
	switch(j[i]){
	case 1:
	  cout << "2" << endl;
	  break;
	case 3:
	  cout << "1" << endl;
	  break;
	}
      }
    else if( !R && S && P ) // グーなし
      for( int i = 0 ; i < 5 ; i++ ){
	switch(j[i]){
	case 2:
	  cout << "1" << endl;
	  break;
	case 3:
	  cout << "2" << endl;
	  break;
	}
      }
    else if( (!R && !S && P) || (!R && S && !P ) || (R && !S && !P ) ){
      for( int i = 0 ; i < 5 ; i++ )
	cout << "3" << endl;
    }
  }
  return 0;
}

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

int main() {
	const int n = 5;
	int hand[n];
	while(cin >> hand[0], hand[0]) {
		int ans[5];
		bool flag[4] = {false};
		flag[hand[0]] = true;
		for(int i = 1; i < n; ++i) {
			cin >> hand[i];
			flag[hand[i]] = true;
		}
		for(int i = 0; i < n; ++i) {
			if(flag[1] && flag[2] && !flag[3]) ans[i] = (hand[i] == 1) ? 1 : 2;
			else if(!flag[1] && flag[2] && flag[3]) ans[i] = (hand[i] == 2) ? 1 : 2;
			else if(flag[1] && !flag[2] && flag[3]) ans[i] = (hand[i] == 3) ? 1 : 2;
			else ans[i] = 3;
			cout << ans[i] << endl;
		}
	}
}