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<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;
int main(void) {
  int i,j;
  vi hand(5);
  while(1){
    vi n(3,0);
    cin>>hand[0];
    if(hand[0]==0)break;
    hand[0]--;
    n[hand[0]]++;
    rep(i,4){
      cin>>hand[1+i];
      hand[1+i]--;
      n[hand[1+i]]++;
    }
    if(n[0]&&n[1]&&n[2])
      rep(i,5)
        cout<<"3"<<endl;
    else if(n[0]==5 || n[1]==5 || n[2]==5)
      rep(i,5)
        cout<<"3"<<endl;
    else if(n[0]&&n[1])//gu choki                      
      rep(i,5)
        if(hand[i])cout<<"2"<<endl;
        else cout<<"1"<<endl;
    else if(n[0]&&n[2])//gu pa                         
      rep(i,5)
        if(hand[i])cout<<"1"<<endl;
        else cout<<"2"<<endl;
    else
      rep(i,5)
        if(hand[i]==1)cout<<"1"<<endl;
        else cout<<"2"<<endl;
  }
}

C++: #include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
using namespace std;
typedef long long  ll;

/** Problem0205 : Rock, Paper, Scissors **/
int main()
{
	int pl[5];
	while (cin>>pl[0], pl[0]!=0) {
		REP(i, 1, 5) cin >> pl[i];
		int r=0, p=0, c=0;
		rep(i, 5) {
			switch (pl[i]) {
				case 1: r++; break;
				case 2: c++; break;
				case 3: p++; break;
			}
		}
		if (r>0 && c>0 && p>0) {
			rep(i, 5) cout << 3 << endl;
		} else if (r==5 || c==5 || p==5) {
			rep(i,5) cout << 3 << endl;
		} else {
			if (r==0) {
				rep(i, 5)
				if (pl[i]==2) cout << 1 << endl;
				else		  cout << 2 << endl;
			} else if (c==0) {
				rep(i, 5)
				if (pl[i]==3) cout << 1 << endl;
				else		  cout << 2 << endl;
			} else {
				rep(i, 5)
				if (pl[i]==1) cout << 1 << endl;
				else		  cout << 2 << endl;
			}
		}
	}
	return 0;
}

C++: #include <stdio.h>
#pragma warning(disable : 4996)
int d[5]; bool p[3];
int main() {
	while (true) {
		for (int i = 0; i < 3; i++) p[i] = false;
		for (int i = 0; i < 5; i++) {
			scanf("%d", &d[i]);
			if (d[i] == 0) break;
			p[d[i] - 1] = true;
		}
		if (d[0] == 0) break;
		if (p[0] && p[1] && p[2]) {
			for (int i = 0; i < 5; i++) {
				printf("3\n");
			}
		}
		else if ((p[0] ? 1 : 0) + (p[1] ? 1 : 0) + (p[2] ? 1 : 0) == 1) {
			for (int i = 0; i < 5; i++) {
				printf("3\n");
			}
		}
		else {
			if (p[0] && p[1]) {
				for (int i = 0; i < 5; i++) {
					if (d[i] == 1) {
						printf("1\n");
					}
					else {
						printf("2\n");
					}
				}
			}
			if (p[1] && p[2]) {
				for (int i = 0; i < 5; i++) {
					if (d[i] == 2) {
						printf("1\n");
					}
					else {
						printf("2\n");
					}
				}
			}
			if (p[2] && p[0]) {
				for (int i = 0; i < 5; i++) {
					if (d[i] == 3) {
						printf("1\n");
					}
					else {
						printf("2\n");
					}
				}
			}
		}
	}
	return 0;
}

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

int winner(int a, int b)
{
  if (a == 1 && b == 2) return (1);
  else if (a == 2 && b == 3) return (2);
  else if (a == 1 && b == 3) return (3);
}

int main()
{
  int input[5];

  while (scanf("%d", &input[0]), input[0]){
    bool check[4] = {false};
    check[input[0]] = true;
    for (int i = 1; i < 5; i++){
      scanf("%d", &input[i]);
      check[input[i]] = true;
    }
    
    if (check[1] && check[2] && check[3]){
      for (int i = 0; i < 5; i++) printf("3\n");
    }
    else {
      int tmp[2];
      for (int i = 1, j = 0; i <= 3; i++){
        if (check[i]) tmp[j++] = i;
      }
      int win = winner(tmp[0], tmp[1]);
      for (int i = 0; i < 5; i++){
        if (input[i] == win){
          printf("1\n");
        }
        else {
          printf("2\n");
        }
      }
    }
  }

  return (0);
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, init, n) for(int i = init; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    vector<int> h(5);
    while(cin >> h[0] && h[0])
    {
        REP(i, 1, 5) cin >> h[i];

        set<int> s;

        rep(i, 5) s.insert(h[i]);

        if(!s.count(1) && s.count(2) && s.count(3))
        {
            rep(i, 5)
            {
                cout << (h[i] == 2 ? 1 : 2) << endl;
            }
        }
        else if(!s.count(2) && s.count(1) && s.count(3))
        {
            rep(i, 5)
            {
                cout << (h[i] == 3 ? 1 : 2) << endl;
            }
        }
        else if(!s.count(3) && s.count(1) && s.count(2))
        {
            rep(i, 5)
            {
                cout << (h[i] == 1 ? 1 : 2) << endl;
            }
        }
        else
        {
            cout << 3 << endl;
        }
    }

    return 0;
}

C++:  #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int arr[5];
 int arr_2[5];
 
 int main()
 {
   int n;
   while(1)
   {
     cin>>n;
     if(n==0) break;
     else arr[0]=n;
     for(int i=1;i<5;i++) cin>>arr[i];
     int min=4;
     int max=0;
     for(int i=0;i<5;i++) arr_2[i]=arr[i];
     sort(arr_2,arr_2+5);
     int count=0;
     for(int i=0;i<4;i++)
     {
       if((arr_2[i+1]-arr_2[i])==1) count++;          
     }
     if(count==2)
     {
       int count2=5;
       while(count2--) cout<<"3"<<endl;          
     }
     for(int i=0;i<5;i++)
     {
       if(arr[i]>max) max=arr[i];
       if(arr[i]<min) min=arr[i];        
     }  
     if(min==1&&max==2)
     {
       for(int i=0;i<5;i++)
       {
         if(arr[i]==1) cout<<"1"<<endl;
         else cout<<"2"<<endl;        
       }                  
     }
     else if(min==2&&max==3)
     {
       for(int i=0;i<5;i++)
       {
         if(arr[i]==2) cout<<"1"<<endl;
         else cout<<"2"<<endl;        
       }                  
     }
     else if(min==1&&max==3)
     {
       for(int i=0;i<5;i++)
       {
         if(arr[i]==1) cout<<"2"<<endl;
         else cout<<"1"<<endl;        
       }                  
     }
     else if(min==max)
     {
       int count3=5;
       while(count3--) cout<<"3"<<endl;     
     }
   }
   //while(1);
   return 0;
 }