Go: // Keitai Message
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2006&lang=jp
package main

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

var table = []string{
	"",
	".,!? ",
	"abc",
	"def",
	"ghi",
	"jkl",
	"mno",
	"pqrs",
	"tuv",
	"wxyz",
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n := nextInt(sc)

	for i := 0; i < n; i++ {
		message := nextString(sc)
		currentButton, count := 0, 0
		for _, word := range message {
			// 確定の処理を書く
			if word == '0' {
				if currentButton == 0 {
					count = 0
					continue
				}
				mod := len(table[currentButton])
				tmp := table[currentButton][(count-1)%mod]
				currentButton, count = 0, 0
				fmt.Printf("%c", tmp)
			} else {
				count++
				currentButton = int(word) - 48 // '0'はASCIIで48
			}
		}
		fmt.Println()
	}
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include <iostream>
using namespace std;
int main(void){
    char code[][5] = {
        {0,0,0,0,0},
        {'.',',','!','?',' '},
        {97,98,99,0,0},
        {100,101,102,0,0},
        {103,104,105,0,0},
        {106,107,108,0,0},
        {109,110,111,0,0},
        {112,113,114,115,0},
        {116,117,118,0,0},
        {119,120,121,122,0}
    };
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string input;
        cin >> input;
        int num = 0;
        int index = 0;
        for (int j = 0; j < input.length(); ++j) {
            if (str[j] == '0') {
                cout << code[num][index];
                num = 0;
                index = 0;
            } else if (!index && !num) {
                num = input[j] - '0';
            } else {
                ++index;
                while(num && !code[num][index]) {
                    if (++index == 5) index = 0;
                }
            }
        }
        cout << endl;
    }
}

C++: #include <stdio.h>
char RB[46]=".,!? abc  def  ghi  jkl  mno  pqrs tuv  wxyz ";char fuego(int here, int len) {int mod;if (here==1) mod=5; else if (here==9 || here==7) mod=4; else mod=3;return RB[(here-1)*5+len%mod];}
int main() {int len=0,val=0,N;char T;scanf("%d%*c",&N);while (N) {T=getchar();if (T>='0' && T<='9') {if (val!=T-48) {if (val) printf("%c",fuego(val,len));val=T-48,len=0;} else len++;} else {val=0,len=0,N--;puts("");}} return 0;}

C++: //Name: Keitai Message
//Level: 1
//Category: シミュレーション,やるだけ
//Note: 

/**
 * やるだけ。
 */
#include <iostream>
#include <string>

using namespace std;

const string tbl[10] = {
    "",
    ".,!? ",
    "abc",
    "def",
    "ghi",
    "jkl",
    "mno",
    "pqrs",
    "tuv",
    "wxyz"
};
bool solve(bool first) {
    string cmd;
    string ans;
    cin >> cmd;
    int row = 0, col = -1;
    for(char c : cmd) {
        if(c == '0') {
            if(col >= 0) ans += tbl[row][col % tbl[row].size()];
            col = -1;
        } else {
            row = c - '0';
            ++col;
        }
    }
    cout << ans << endl;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);

    int N;
    cin >> N;
    bool first = true;
    while(N--) {
        solve(first);
        first = false;
    }
    return 0;
}

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

using namespace std;
 
string key[] = {"",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
 
int main(){
    int n;
     
    cin >> n;
    while(n--){
        string str,tmp = "";
        cin >> str;
 
        int cnt = 0 ,t = 0;
        string s = "";
        for(int i = 0 ; i < str.size() ; i++){
            if(str[i]=='0'){
                if(!cnt) continue;
                tmp += key[t][cnt-1];
                t = cnt = 0;
            }
            else{
                t = str[i]-'0';
                if((cnt>2)&&(t==2||t==3||t==4||t==5||t==6||t==8)) cnt -= 3;
                else if((cnt>3)&&(t==7||t==9)) cnt -= 4;
                else if((cnt>4)&&t==1) cnt -= 5;
                cnt++;
            }
        }
        cout << tmp << endl;
    }
     
    return 0;
}

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

char const mozi1[]={'.',',','!','?',' '},mozi2[]={'a','b','c'},mozi3[]={'d','e','f'},mozi4[]={'g','h','i'},mozi5[]={'j','k','l'},mozi6[]={'m','n','o'},mozi7[]={'p','q','r','s'},mozi8[]={'t','u','v'},mozi9[]={'w','x','y','z'};
void henkan(char *);
char mozi(int,char);
int main(){
	int n;
	cin>>n;

	for(int i=0;i<n;i++){
		char * keitai=new char[1024];
		scanf("%s",keitai);
		henkan(keitai);
		delete[]keitai;
	}
	return 0;
}

void henkan(char * keitai){
	char *hyouzi=new char[72];
	fill(hyouzi,hyouzi+72,0);
	int length=strlen(keitai);
	int cnt=0;
	
	for(int i=0;i<length;i++){
		if(keitai[i]=='0')	continue;
		else{
			int kazu=1;
			while(keitai[i+1]!='0'){
				kazu++;
				i++;
			}
			hyouzi[cnt]=mozi(kazu,keitai[i]);
			i++;
			cnt++;
		}
	}
	
	cout<<hyouzi<<endl;
	delete[] hyouzi;
}
char mozi(int kazu,char keitai){
	switch (keitai)
	{
	case '1':
		kazu=kazu%5-1;
		if(kazu==-1)	return mozi1[4];
		return mozi1[kazu];
		
	case '2':
		kazu=kazu%3-1;
		if(kazu==-1)	return mozi2[2];
		return mozi2[kazu];
		
	case '3':
		kazu=kazu%3-1;
		if(kazu==-1)	return mozi3[2];
		return mozi3[kazu];
		
	case '4':
		kazu=kazu%3-1;
		if(kazu==-1)	return mozi4[2];
		return mozi4[kazu];
		
	case '5':
		kazu=kazu%3-1;
		if(kazu==-1)	return mozi5[2];
		return mozi5[kazu];
		
	case '6':
		kazu=kazu%3-1;
		if(kazu==-1)	return mozi6[2];
		return mozi6[kazu];
		
	case '7':
		kazu=kazu%4-1;
		if(kazu==-1)	return mozi7[3];
		return mozi7[kazu];
		
	case '8':
		kazu=kazu%3-1;
		if(kazu==-1)	return mozi8[2];
		return mozi8[kazu];
		
	case '9':
		kazu=kazu%4-1;
		if(kazu==-1)	return mozi9[3];
		return mozi9[kazu];
	default:
		return NULL;
	}
}

C++: #if 1
  #include <bits/stdc++.h>
#else
  #include "../../bits/stdc++.h"
#endif

#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(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))

using namespace std;

typedef pair<int, int> P;
#define pb push_back
#define mp make_pair
#define ft first
#define sd second

char w[9][5] = {
  {'.', ',', '!', '?', ' '},
  {'a', 'b', 'c', ' ', ' '},
  {'d', 'e', 'f', ' ', ' '},
  {'g', 'h', 'i', ' ', ' '},
  {'j', 'k', 'l', ' ', ' '},
  {'m', 'n', 'o', ' ', ' '},
  {'p', 'q', 'r', 's', ' '},
  {'t', 'u', 'v', ' ', ' '},
  {'w', 'x', 'y', 'z', ' '}
};

int n;
char c[1030];
int t;
P s[80];
char o[80];
int l;

void input(){
  cin>>c;
  l = strlen(c);
  REP(i, 80)s[i] = mp(0, 0);
}

void solve(){
  t=0;

  REP(i, l) {
    if(c[i]=='0') {
      if(s[t].ft==0)continue;
      else t++;
    }else {
      if(s[t].ft==0)s[t].ft=c[i]-'0';
      else s[t].sd++;
    }
  }

  REP(i, t) {
    s[i].ft--;
    o[i] = w[s[i].ft][s[i].sd%(s[i].ft==0?5:(s[i].ft==6||s[i].ft==8?4:3))];
  }
  o[t] = '\0';
  cout<<o<<endl;
}

int main(){
  cin.tie(0);
  
  cin>>n;
  REP(i, n) {
    input();
    solve();
  }
  
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main()
{ 
  int n; cin>>n;
  vector<string> ans;
  while(n--)
  {
    string on=".,!? ";
    string s; cin>>s;
    int cnt=0 ,num=0;
    string tmp;
    for(int i=0; i<s.size(); ++i)
    {
      if(num==s[i]-'0') cnt++;
      else 
      {
        if(num==1) tmp+=on[cnt%5];
        else if(num==7) tmp+=cnt%4+'p';
        else if(num==8) tmp+=cnt%3+'t';
        else if(num==9) tmp+=cnt%4+'w';
        else if(num>1) tmp+=cnt%3+'a'+3*(num-2);
        cnt=0;
        num=s[i]-'0';
      }
    }
    ans.emplace_back(tmp);
  }
  for(auto e:ans) cout<<e<<"\n";

  return 0;
}