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>
#include <string>

using namespace std;

int main()
{
    string messages[9]= {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        string msg;
        int count = 0;
        char prev = '0';

        cin >> msg;

        for (int j = 0; j < msg.size(); j++) {
            char c = msg[j];

            if (c == '0') {
                if (prev == '1') {
                    cout << messages[0][(count-1) % 5];
                } else if (prev == '2') {
                    cout << messages[1][(count-1) % 3];
                } else if (prev == '3') {
                    cout << messages[2][(count-1) % 3];
                } else if (prev == '4') {
                    cout << messages[3][(count-1) % 3];
                } else if (prev == '5') {
                    cout << messages[4][(count-1) % 3];
                } else if (prev == '6') {
                    cout << messages[5][(count-1) % 3];
                } else if (prev == '7') {
                    cout << messages[6][(count-1) % 4];
                } else if (prev == '8') {
                    cout << messages[7][(count-1) % 3];
                } else if (prev == '9') {
                    cout << messages[8][(count-1) % 4];
                }
                count = 0;
            } else {
                count++;
            }
            prev = msg[j];
        }
        cout << endl;
    }

    return 0;
}

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

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

  int a,count=0,c[100],d;
  char b[100][1025];
  cin>>a;
  for(int i=0;i<a;i++){
    scanf("%s",b[i]);
    c[i]=strlen(b[i]);
    for(int j=0;j<c[i];j++){
      if(b[i][j]!='0')count++;
      else
	if(b[i][j-1]!=0){
	  d=(int)(b[i][j-1])-48;

	  if(d==1)
	    if(count%5!=0)
	      cout<<m[d-1][count%5-1];
	    else cout<<m[d-1][4];

	  else if(d==7 || d==9)
	    if(count%4!=0)
	      cout<<m[d-1][count%4-1];
	    else cout<<m[d-1][3];

	  else
	    if(count%3!=0)
	      cout<<m[d-1][count%3-1];
	    else cout<<m[d-1][2]; 
	  count=0;
	}
    }
    cout<<endl;
  }
  return 0;
}
#include<iostream>
#include<cstdio>
#include<cstring>

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

  int a,count=0,c[100],d;
  char b[100][1025];
  cin>>a;
  for(int i=0;i<a;i++){
    scanf("%s",b[i]);
    c[i]=strlen(b[i]);
    for(int j=0;j<c[i];j++){
      if(b[i][j]!='0')count++;
      else
	if(b[i][j-1]!=0){
	  d=(int)(b[i][j-1])-48;

	  if(d==1)
	    if(count%5!=0)
	      cout<<m[d-1][count%5-1];
	    else cout<<m[d-1][4];

	  else if(d==7 || d==9)
	    if(count%4!=0)
	      cout<<m[d-1][count%4-1];
	    else cout<<m[d-1][3];

	  else
	    if(count%3!=0)
	      cout<<m[d-1][count%3-1];
	    else cout<<m[d-1][2]; 
	  count=0;
	}
    }
    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++)
		{
			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;
			}
			d = c;
		}
		cout << endl;
	}
}

C++: #include <bits/stdc++.h>
#include <tuple>
#include <iterator>
using namespace std;
using ll = long long;

char t[][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 main()
{
  int n;
  cin >> n;
  vector<string> ans;
  for (int i = 0; i < n; ++i)
  {
    string s;
    cin >> s;
    string sum = "";
    int cnt = 0;
    char c = '0';
    for (int j = 0; j < s.size(); ++j)
    {
      if (s[j] == '0')
      {
        if (c == '0')
          continue;
        if ((c - '0') == 1)
          sum += t[c - '0'][(cnt - 1) % 5];
        else if ((c - '0') == 7 || (c - '0') == 9)
          sum += t[c - '0'][(cnt - 1) % 4];
        else
          sum += t[c - '0'][(cnt - 1) % 3];
        cnt = 0;
        c = '0';
      }
      else
      {
        c = s[j];
        cnt++;
      }
    }
    ans.push_back(sum);
  }
  for (auto &e : ans)
    cout << e << endl;

  return 0;
}

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

using namespace std;

struct wait{
	char num;
	int count;
};

void out(int, int);

int main(){
	int n;
	string input;
	struct wait now;
	int i, j;
	
	cin >> n;
	for(i = 0; i < n; i++){
		now.count = 0;
		cin >> input;
		
		for(j = 0;j < input.size(); j++){
			if(input[j] == '0'){
				out(now.num - '0', now.count);
				now.count = 0;
			}
				
			else{
				now.num = input[j];
				now.count++;
			}
		}
		cout << endl;
	}
	
	return 0;
}

void out(int num, int count){
	char output[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 size[] = {5, 3, 3, 3, 3, 3, 4, 3, 4};
	int which;
	
	if(count == 0)
		return;
	
	if(count % size[num - 1] == 0)
		which = size[num - 1] - 1;
	else
		which = count % size[num - 1] - 1;
	cout << output[num - 1][which];
}

C++: #include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <queue>
using namespace std;

void p(int nu, int key){
//cout<<"dckjw"<<nu<<" "<<key<<endl;
string s[10]={"",".,!?","cab","fde","igh","ljk","omn","spqr","vtu","zwxy"};
if(key==1){
nu=nu%5;
if(nu==0) cout<<" ";
else cout<<s[1][nu-1];
}
if(key==2){
nu=nu%3;
//cout<<s[2];
cout<<s[2][nu];
}
if(key==3){
nu=nu%3;
cout<<s[3][nu];
}
if(key==4){
nu=nu%3;
cout<<s[4][nu];
}
if(key==5){
nu=nu%3;
cout<<s[5][nu];
}
if(key==6){
nu=nu%3;
cout<<s[6][nu];
}
if(key==7){
nu=nu%4;
cout<<s[7][nu];
}
if(key==8){
nu=nu%3;
cout<<s[8][nu];
}
if(key==9){
nu=nu%3;
cout<<s[9][nu];
}


}
int main(){
string s;
int n,l;
cin>>n;
for(int www=0;www<n;www++){
cin>>s;
l=s.length();
int nu=1,key;
key=s[0]-'0';


for(int j=0;j<l-1;j++){
if(s[j]!=s[j+1]){
p(nu,key);
nu=1;
key=s[j+1]-'0';
}
else{
nu++;
}

}
p(nu,key);
cout<<endl;
}
return 0;
}