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

package main

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

// 標準入力を取得するScannerのインスタンスを作成
var scanner = bufio.NewScanner(os.Stdin)

// 標準入力で各行を読み込みstringとして返す
func readLine() string {
	if scanner.Scan() {
		return scanner.Text()
	}
	return ""
}

func main() {
	// 1: . , ! ? (スペース)
	// 2: a b c
	// 3: d e f
	// 4: g h i
	// 5: j k l
	// 6: m n o
	// 7: p q r s
	// 8: t u v
	// 9: w x y z
	// 0: 確定ボタン

	// 改行から空白区切りに変更
	scanner.Split(bufio.ScanWords)
	line, _ := strconv.Atoi(readLine()) // 5行標準入力が続く

	table := []string{
		"",      // 0 index調整ためダミーデータ
		".,!? ", // 1
		"abc",   // 2
		"def",   // 3
		"ghi",   // 4
		"jkl",   // 5
		"mno",   // 6
		"pqrs",  // 7
		"tuv",   // 8
		"wxyz"}  // 9

	// 5行分の標準入力を格納するsliceを作成する
	messages := make([]string, 0, line)

	// sliceに標準入力の内容を格納する
	for i := 0; i < line; i++ {
		messages = append(messages, readLine()) // messages=[20 220 222220 44033055505550666011011111090666077705550301110 000555555550000330000444000080000200004440000]
	}

	// 各行毎に解析する
	for _, message := range messages { // message=000555555550000330000444000080000200004440000
		// 0で分割する
		messageSlice := strings.Split(message, "0") // messageSlice=[   55555555    33    444    8    2    444    ]
		for _, word := range messageSlice {
			if word == "" {
				// NOP.
				// 0をセパレーターにしているので空文字がsliceに格納されてい箇所がある
				// 何もしない
			} else { // word=55555555
				// 一文字取り出しコード値をASCII文字に変換する
				ascii := string((word[0])) // word[0]=5

				// ASCII文字からintへ変換する(tableのindexになる)
				number, _ := strconv.Atoi(ascii)

				// 入力回数をカウントする
				count := len(word) // 5

				// 同じ数字を続けて入力すると変化する文字はループすることを考慮する
				for count > len(table[number]) { // 5 > 3
					count -= len(table[number]) // 2
				}

				// キー配列
				keys := table[number]                   //jkl
				fmt.Printf("%s", string(keys[count-1])) //k
			}
		}
		fmt.Println() // 改行
	}
}

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

int key[10];

// プロトタイプ宣言
void Reset(void);
char Output(int);
// ここまで

int main(){
	Reset();

	int n;	cin>>n;
	for(int i=0;i<n;i++){
		string ans="";
		string s;
		cin>>s;
		for(int j=0;j<s.length();j++){
			int num=s[j]-'0';
			//printf("<%d>\n",num);

			if(num==0){
				for(int k=1;k<=9;k++){
					if(key[k]<0)continue;
					else ans+=Output(k);
				}
				Reset();
			}else{
				key[num]++;
			}
		}

		cout<<ans<<endl;
	}


	return 0;
}



void Reset(void){ for(int i=0;i<10;i++) key[i]=-1; }
char Output(int num){
	char word[10][5]={
		{'A','B','C','D','E'},// 使わない
		{'.',',','!','?',' '},
		{'a','b','c','F','G'},
		{'d','e','f','H','I'},
		{'g','h','i','J','K'},
		{'j','k','l','L','M'},
		{'m','n','o','N','O'},
		{'p','q','r','s','P'},
		{'t','u','v','Q','R'},
		{'w','x','y','z','S'}};

	int tmp=key[num];
	switch(num){
		case 1:
			tmp%=5;
			break;
		case 7:
		case 9:
			tmp%=4;
			break;
		default:
			tmp%=3;
			break;
	}

	return word[num][tmp];
}

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

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  string tenkey[10] = {".,!? ",
                     "abc",
                     "def",
                     "ghi",
                     "jkl",
                     "mno",
                     "pqrs",
                     "tuv",
                     "wxyz"};
  cin >> n;

  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;

    for (int j = 0; j < s.size(); j++) {
      int count = -1;
      int num = s[j] - '0';
      while (s[j] != '0') {
        count++;
        j++;
      }
      //cout << "num-1 = " << num-1 << endl;                                                                                                      
      //cout << "count = " << count << endl;                                                                                                      
      if (count >= 0) {
        //cout << "tenkey[num-1].size() = " << tenkey[num-1].size() << endl;                                                                      
        cout << tenkey[num-1][count % tenkey[num-1].size()];
      }
    }
    cout << endl;
  }
  return 0;
}

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

int main(){
    int n;
    char ans[100];
    char s[1100];
    int value;
    int h = 0,w,cnt;
    bool judge;
    char tmp[9][6] = {{".,!? "},{"abc"},{"def"},{"ghi"},{"jkl"},{"mno"},{"pqrs"},{"tuv"},
        {"wxyz"}};
    cin >> n;
    while(n--){
        value = 0;
        memset(ans,0,sizeof(ans));
        memset(s,0,sizeof(s));
        cin >> s;
        for(int i=0;i<strlen(s);i++){
            cnt = 0;
            h = 0;
            while(1){
                if(s[i] == '0') break;
                h = s[i]%'0';
                cnt++;  
                i++;
            }
            w = cnt-1;
            judge = false;
            switch (h-1){
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                case 7:
                    ans[value] = tmp[h-1][w%3];
                    judge = true;
                    break;
                case 6:
                case 8:
                    ans[value] = tmp[h-1][w%4];
                    judge = true;
                    break;
                case 0:
                    ans[value] = tmp[h-1][w%5];
                    judge = true;
            }
            if(judge) value++;
        }
        cout << ans << endl;
    }
}

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

int main()
{
	int n, p, cnt;
	string key[] = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
	string str;
	
	cin >> n;
	while (cin >> str) {
		for (char& c : str) {
			n = c - '0';
			if (n) {
				cnt++;
			} else {
				cout << key[p][(cnt-1) % key[n].size]
				cnt = 0;
			}
			p = n;
		}
		cout << endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
int main()
{
	int n, i, j, k, c, d, x;
	char s[1025], t[10][6] = {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> s;
		for (j = x = 0, d = 0; j < strlen(s); j++, d = c)
		{
			c = s[j] - '0';
			if (c == 0 && d != 0)
				cout << t[d-1][x%strlen(t[d-1])];
			else if (d == c)
				x++;
			else
				x = 0;
		}
		cout << endl;
	}
}

C++: #include <bits/stdc++.h>
#define rep( i, begin, end) for( int i = begin; i < end; i++ )
using namespace std;
 
string button[10] = { "", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };
 
int main() {
    int n;
    cin >> n;
    rep( i, 0, n ) {
        string input, message = "";
        cin >> input;
        int key = 0, position = 0;
        rep( i, 0, input.size() ) {
            if ( input[i] == '0' ) {
                if ( key == 0 )
                    continue;
                position %= button[key].size();
                message += button[key][position];
                key = 0;
                position = 0;
            }
            else if ( key == 0 ) {
                key = input[i] - '0';
                position = 0;
            }
            else if ( key == input[i] - '0') {
                position++;
            }
        }
        cout << message << endl;
    }
    
    return 0;
}