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<iostream>
#include<cstring>

using namespace std;

string outputWord(string str);

int main() {
  int n;
  string tmp;
  cin>>n;
  getline(cin, tmp);
  while(n--) {
    string inputStr;
    getline(cin, inputStr);    
    cout<<outputWord(inputStr)<<endl;
  }
}

string outputWord(string str) {
  string ans, tmp;

  for(int i=0; i<str.length(); i++) {
    switch(str[i]) {
    case '0':
      ans += tmp;
      tmp.clear();
      break;
    case '1':
      if(tmp.length()==0 || tmp==" ") {
	tmp = ".";
      }
      else if(tmp == ".") {
	tmp = ",";
      }
      else if(tmp == ",") {
	tmp = "!";
      }
      else if(tmp == "!") {
	tmp = "?";
      }
      else if(tmp == "?") {
	tmp = " ";
      }
      break;
    case '2':
      if(tmp.length()==0 || tmp=="c") {
	tmp = "a";
      }
      else if(tmp == "a") {
	tmp = "b";
      }
      else if(tmp == "b") {
	tmp = "c";
      }
      break;
    case '3':
      if(tmp.length()==0 || tmp=="f") {
	tmp = "d";
      }
      else if(tmp == "d") {
	tmp = "e";
      }
      else if(tmp == "e") {
	tmp = "f";
      }
      break;
    case '4':
      if(tmp.length()==0 || tmp=="i") {
	tmp = "g";
      }
      else if(tmp == "g") {
	tmp = "h";
      }
      else if(tmp == "h") {
	tmp = "i";
      }
      break;
    case '5':
      if(tmp.length()==0 || tmp=="l") {
	tmp = "j";
      }
      else if(tmp == "j") {
	tmp = "k";
      }
      else if(tmp == "k") {
	tmp = "l";
      }
      break;
    case '6':
      if(tmp.length()==0 || tmp=="o") {
	tmp = "m";
      }
      else if(tmp == "m") {
	tmp = "n";
      }
      else if(tmp == "n") {
	tmp = "o";
      }
      break;
    case '7':
      if(tmp.length()==0 || tmp=="s") {
	tmp = "p";
      }
      else if(tmp == "p") {
	tmp = "q";
      }
      else if(tmp == "q") {
	tmp = "r";
      }
      else if(tmp == "r") {
	tmp = "s";
      }
      break;
    case '8':
      if(tmp.length()==0 || tmp=="v") {
	tmp = "t";
      }
      else if(tmp == "t") {
	tmp = "u";
      }
      else if(tmp == "u") {
	tmp = "v";
      }
      break;
    case '9':
      if(tmp.length()==0 || tmp=="z") {
	tmp = "w";
      }
      else if(tmp == "w") {
	tmp = "x";
      }
      else if(tmp == "x") {
	tmp = "y";
      }
      else if(tmp == "y") {
	tmp = "z";
      }
      break;
    }
  }

  return ans;
}

C++: #include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
int main() {
	string a;
	string d[10] = { "",".,!?","abc","def","ghi","jkl","mno",
		"pqrs","tuv","wxyz" };
	while (cin >> a) {
		char b;
		string c = "";
		for (int i = 0; i < a.length(); i++) {
			b = a[i];
			int i2 = i;
			while (a[i] == b) i++;
			int sum = i - i2;
			sum %= d[(int)b - '0'].length();
			sum--;
			c += d[(int)b-'0'][sum];
		}
		cout << c << endl;
	}
}

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

using namespace std;

int main(){

	string data[] = { ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };
	char inp;
	int n, cnt, num;
	string ans;

	cin >> n;

	getchar();

	for (int i = 0; i < n; i++){

		cnt = 0;
		ans = ("");

		while (1){

			inp = getchar();

			if (inp == '\n') break;
			if (inp != '0'){
				num = inp - '0';
				cnt++;
			}
			else{
				if (cnt > 0){
					ans += data[num-1][(cnt-1)%data[num-1].size()];
					cnt = 0;
				}
			}
		}

		cout << ans << endl;
	}

	return 0;
}

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

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

string in;
int col=-1, row=0;
int num;
int state = 0;

int main(){
  int N;
  cin >> N;
  while(N--){
    cin.ignore();
    while(getline(cin,in)){
      bool onlyzero = true;
      for(int i = 0; i < in.length(); i++)
	if(in[i] != '0') onlyzero = false;

      if(onlyzero){
	cout << endl;
	continue;
      }

      for(int i = 0; i < in.length(); i++){
	if(in[i] == '0'){
	  if(col == -1) col++;
	  if(row >= 2 && row <= 6 || row == 8) num = 3;
	  else if(row == 1) num = 5;
	  else num = 4;
	
	  if(data[row][col%num] != 'E'){
	    cout << data[row][col%num];
	    state = 1;
	  }
	  col = -1;
	  row = 0;
	}else{
	  col++;
	  row=in[i]-'0';
	}
	if(i == in.length()-1){
	  if(state == 1) cout << endl;
	  state = 0;
	  col = -1;
	  row = 0;
	}
	
      }
      if(data[row][col%num] != 'E'){
	cout << data[row][col%num];
	//state = 1;
      }
      if(state == 1) cout << endl;
    }
  }
  return 0;
}

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

using namespace std;

int main()
{
  string code[] = {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
  int len[] = {5, 3, 3, 3, 3, 3, 4, 3, 4};
  
  int N;
  cin >> N;
  while(N--){
    string s;
    cin >> s;
    char c = '#';
    int idx = 0;
    for(int i = 0; i < s.size(); i++){
      if(s[i] == '0'){
	if(c != '#') cout << c;
	c = '#';
	idx = 0;
      } else {
	c = code[s[i]-'0'-1][idx];
	idx = (idx + 1) % len[s[i]-'0'-1];
      }
    }
    cout << endl;
  }

  return 0;
}