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 <map>
#include <string>
#include <typeinfo>
using namespace std;

int main(){
  int n, l, c, s;
  string str, ans;
  map<int, string> m;
  m[1] = ".,!? ";
  m[2] = "abc";
  m[3] = "def";
  m[4] = "ghi";
  m[5] = "jkl";
  m[6] = "mno";
  m[7] = "pqrs";
  m[8] = "tuv";
  m[9] = "wxyz";
  cin >> n;
  for (int i = 0; i < n; ++i){
    cin >> str;
    c = 0;
    l = str.length();
    ans = "";
    s = 0;
    for (int j = 0; j < l; ++j){
      int S = str[j] - 48;
      if (s == S) c++;
      else  if (S == 0){
	c %= m[s].length();
	ans += m[s][c];
	c = -1;
	s = S;
      }else{
	s = S;
	c = 0;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

#define PI 4*atan(1)
#define INF 1e8

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

vector<string> button = {".,!?",
           "abc",
           "def",
           "ghi",
           "jkl",
           "mno",
           "pqrs",
           "tuv",
           "wxyz"};


int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    string s;
    cin >> s;
    int cnt = 0;
    for(int j = 0; j < s.size(); j++){
      if(s[j] == '0'){
        if(cnt != 0){
          int num = s[j-1] - '0';
          char c = button[num - 1][(cnt-1)%button[num-1].size()];
          cout << c;
          cnt = 0;
        }
      }else{
        cnt++;
      }
    }
    cout << endl;
  }
}

C++: #include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    cin >> n;
    string a[10] = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxvz"};
    while (n--){
        string s;
        cin >> s;
        int p = -1;
        REP(i,s.length()){
            int x = s[i] - '0';
            if (x == 0 && p >= 0){
                int y = s[i-1]-'0';
                cout << a[y][p % a[y].length()];
                p = -1;
            }
            if (x > 0) p++;
        }
        cout << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <queue>
#include <string>
using namespace std;
int main(){
	string bottun[10] = { "0", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };
	queue<char> str;
	int n, i;
	cin >> n;
	while( n-- > 0 ){
		char s[1025];
		cin >> s;
		for( i = 0; s[i] != '\0'; i++ ){
			str.push(s[i]);
		}
		int t = 0, num = 0;
		while( !str.empty() ){
			if( str.front() == '0' && num != 0 ){
				cout << bottun[num][(t-1)%bottun[num].length()];
				t = -1;
			}
			num = (int)(str.front() - '0');
			str.pop();
			t++;
		}
		cout << endl;
	}
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>

using namespace std;

#define all(i) i.begin(), i.end()
#define rep(i,n) for(int i=0;i<n;i++)

int main()
{
	int num = 0; cin >> num;
	string dat[12] = { "", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };
	rep(i, num)
	{
		string str; cin >> str;
		vector<int> hit(10, 0);
		rep(j, (int)str.size())
		{
			hit[str[j] - '0'] += 1;
			if (j == 0 || str[j - 1] == '0') {}
			else if (str[j] == '0')
			{
				int tmp = str[j - 1] - '0', n = hit[tmp];
				while (1)
				{
					if (n <= (int)dat[tmp].size()) { break; }
					n -= (int)dat[tmp].size();
				}
				printf("%c", dat[tmp][n - 1]);
				rep(i, 10) { hit[i] = 0; }
			}
		}
		printf("\n");
	}
	return 0;
}

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

string s,ans;
int n,num,now;
int csize[10]={0,5,3,3,3,3,3,4,3,4};
char btn[10][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 i,a,j;
  cin >> n;
  for(a=0;a<n;a++){
    ans="";
    cin >> s;
    for(i=0;i<s.size();i++){
      now = s[i]-'0';
      num=0;
      if(now==0)continue;
      while(s[++i]==now+'0')num++;
      ans+=btn[now][num%csize[now]];
    }
    cout << ans << endl;
  }
  return 0;
}

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) {
		string c = "";
		 for (int i = 0; i < a.length();) {
			while (a[i] == '0'&&i<a.length())i++;
			if (i == a.length()) break;
			int j = i;
			while (a[j] == a[i]&&i<a.length()) {
				i++;
			}
			int sum = i - j-1;
			sum %= d[(int)a[j] - '0'].length();
			if(i<a.length()&&a[i]=='0')c += d[(int)a[j] - '0'][sum];
		}
		 if (c != "") cout << c << endl;
	}
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[1080], b[1080];
int n, m;

string button[10] = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
string str;

char _str[10800];
void output(int val, int cnt){
	if(val == 0)return;
	cout << button[val][(cnt-1) % button[val].size()];
}


int main(){
	while(~scanf(" %s", _str)){
		str = _str;
		int val = 0;
		int cnt = 0;
		for(int i = 0;i < str.size();i++){
			if(str[i] == '0'){
				output(val, cnt);
				val = cnt = 0;
			}
			else{
				val = str[i] - '0';
				cnt++;
			}
		}
		output(val, cnt);
		cout << endl;
	}
	return 0;
}

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

using namespace std;

int main(){
	char moji[10][6];
	strcpy(moji[1],".,!? ");
	strcpy(moji[2] ,"abc  ");
strcpy(moji[3], "def  ");
strcpy(moji[4],"ghi  ");
strcpy(moji[5],"jkl  ");
strcpy(moji[6],"mno  ");
strcpy(moji[7],"pqrs ");
strcpy(moji[8],"tuv  ");
strcpy(moji[9],"wxyz ");

	string str;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>str;
		int cnt=0;
		int num=0;
		for(int j=0;j<str.size();j++){
			if(str.at(j)=='0')continue;
			cnt=0;
			num=str.at(j)-'0';
			if(j==str.size()-2){
				cout<<moji[num][cnt];
				break;
			}

			while(str.at(j)==str.at(j+1)){
				cnt++;
				j++;
				if(j==str.size()-2){
					break;
				}
			}

			if(num==1){
				cnt%=5;
			}
			else if(num==7||num==9){
				cnt%=4;
			}
			else{
				cnt%=3;
			}

			cout<<moji[num][cnt];
		}
		cout<<endl;
	}
	return 0;
}