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 <algorithm>
#include <iostream>
#include <limits.h>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX/2-1

using namespace std;

int main() {
  int n, pre, cur, count;
  string s;
  string org[] = {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
  vector<string> button(org, org+9);
  cin >> n;
  while (n--) {
    cin >> s;
    pre = 0;
    for (int i = 0; i < s.length(); i++) {
      cur = (int)(s[i]-'0');
      if (pre == 0) {
        if (cur != 0) {
          pre = cur;
        }
      } else {
        if (cur == 0) {
          cout << button[pre-1][count];
          pre = 0;
          count = 0;
        } else {
          count = (count+1)%button[pre-1].length();
        }
      }
    }
    cout << el;
  }
}

C++: #include <iostream>
#include <string>
#include <cstdlib>
#include <sstream>
using namespace std;
int main(){
	int N;
	cin >> N;
	for(int i=0;i<N;i++){
		string key[]={".,!?, ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
		string input;
		cin>>input;
		stringstream b(input);
		int num=0,count=0;
		while(1){
			char c;
			if(b>>c)break;
			int input=c-'0';
			if(input!=0){
				count++;
				num=input;
			}
			else {
				if(count!=0)
					cout<<key[num-1][count%key[num-1].size()];
				num=0;count=0;
			}
		}
		cout<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
using namespace std;
int main(void){
    vector<string> str(9);
    str[0]=".,!? ";
    str[1]="abc";
    str[2]="def";
    str[3]="ghi";
    str[4]="jkl";
    str[5]="mno";
    str[6]="pqrs";
    str[7]="tuv";
    str[8]="wxyz";
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        string x;
        string ans="";
        cin >> x;
        int count;
        if(x[0]!='0'){
            count=1;
        }else{
            count=0;
        }
        
        for(int j=1;j<x.length();j++){
            if(x[j]=='0'){
                if(x[j-1]!='0'){
                    if(count > str[(x[j-1]-'0')-1].length()){
                        count = count%str[(x[j-1]-'0')-1].length();
                        if(count == 0){
                            count =str[(x[j-1]-'0')-1].length();
                        }
                    }
                    ans+=str[(x[j-1]-'0')-1][count-1];
                }
                count=0;
            }else{
                count++;
            }
        }
        cout << ans << endl;
    }
}

C++: #include<stdio.h>
#include<iostream>
#include<string>

using namespace std;

int main(){

	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		string str;
		char last;
		char key[10][13]={
			{' '},
			{' ','.',',','!','?',' '},
			{' ','a','b','c','a','b','c','a','b','c','a','b','c'},
			{' ','d','e','f','d','e','f','d','e','f','d','e','f'},
			{' ','g','h','i','g','h','i','g','h','i','g','h','i'},
			{' ','j','k','l','j','k','l','j','k','l','j','k','l'},				
			{' ','m','n','o','m','n','o','m','n','o','m','n','o'},
			{' ','p','q','r','s','p','q','r','s','p','q','r','s'},
			{' ','t','u','v','t','u','v','t','u','v','t','u','v'},
			{' ','w','x','y','z','w','x','y','z','w','x','y','z'},								
		};
		cin >> str;
		int array[10],i;
		for(i=0;i<10;i++){
			array[i]=0;
		}
		last = str[0];
		for(i=0;i<str.size();i++){
			array[str[i]-0x30]++;
			if(array[str[i]-0x30] > 12 && last!=1) array[str[i]-0x30]=1;
			if(array[1] > 5) array[1]=1;
			if(str[i]=='0' && last!='0'){
				// cout << last << ':' << array[last-0x30] << endl;
				cout <<  key[(last-0x30)][array[last-0x30]];
				for(int l=0;l<10;l++){
					array[l]=0;
				}
			}
			last = str[i];
		}
		cout << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
    vector<string> v;
    v.push_back("");
    v.push_back(".,!? ");
    v.push_back("abc");
    v.push_back("def");
    v.push_back("ghi");
    v.push_back("jkl");
    v.push_back("mno");
    v.push_back("pqrs");
    v.push_back("tuv");
    v.push_back("wxyz");
    string s;
    int n;
    scanf("%d",&n);
    for(int k=0;k<n;k++) {
        cin>>s;
        int num=0,cnt=0;
        for(int i=0;i<s.size();i++) {
            if(s[i]=='0') {
                if(num) putchar(v[num][(cnt-1)%v[num].size()]);
                num=cnt=0;
            }else {
                num=s[i]-'0';
                cnt++;
            }
        }
        putchar('\n');
    }
}

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

using namespace std;

int main(){
	int n;
	cin >> n;
	while(n--){
		string s; cin >> s;
		string t[] = {" ", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
		string res = "";
		int cnt = 0, idx = 0;
		for(int i=0;i<s.size();i++){
			if(s[i]=='0'){
				if(idx!=0){
					res += t[idx][cnt];
				}
			}
			if(idx == s[i]-'0'){
				cnt = (cnt+1)%t[idx].size();
			} else {
				cnt = 0;
			}
			idx = s[i]-'0';
		}
		cout << res << endl;
	}
}