Go: package main

import (
	"bytes"
	"fmt"
)

//Ktai has a keyboard and a state.
type Ktai struct {
	keyboard KeyBoard
	textBuf  *bytes.Buffer
}

// KeyBoard is type of a map.
type KeyBoard map[rune]string

// KEYBOARD that Ktai has
var KEYBOARD = KeyBoard{
	'0': "",
	'1': ".,!? ",
	'2': "abc",
	'3': "def",
	'4': "ghi",
	'5': "jkl",
	'6': "mno",
	'7': "pqrs",
	'8': "tuv",
	'9': "wxyz",
}

func main() {
	var N int
	fmt.Scanf("%d", &N)
	ktai := &Ktai{
		KEYBOARD, &bytes.Buffer{},
	}
	for i := 0; i < N; i++ {
		var numstr string
		fmt.Scanf("%s", &numstr)
		ktai.feed(numstr)
		ktai.print()
	}
}

func (ktai *Ktai) feed(str string) {
	var char *byte
	for _, v := range str {
		if v == '0' {
			if char != nil {
				ktai.textBuf.WriteByte(*char)
				char = nil
			}
			continue
		} else {
			runestring := ktai.keyboard[v]
			idx := ktai.indexOf(char, runestring)
			next := (idx + 1) % len(runestring)
			c := runestring[next]
			char = &c
		}
	}
}

func (ktai *Ktai) indexOf(ch *byte, str string) int {
	if ch == nil {
		return -1
	}
	r := rune(*ch)
	idx := -1
	for i, v := range str {
		if r == v {
			idx = i
			break
		}
	}
	return idx
}

func (ktai *Ktai) print() {
	fmt.Println(ktai.textBuf.String())
	ktai.textBuf.Reset()
}

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

vector<pair<int, int>> perse(string s) {
  vector<pair<int, int>> v;
  int cnt = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == '0') {
      if (cnt) v.push_back(make_pair(s[i - 1] - '0', cnt));
      cnt = 0;
    }
    else ++cnt;
  }

  return v;
}

char c[10][10] = {
  {},
  {'.', ',', '!', '?', ' '},
  {'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'}
};

char ans(int a, int b) {
  b--;
  if (a == 1) b %= 5;
  else if (a == 7 || a == 9) b %= 4;
  else b %= 3;
  return c[a][b];
}

int main() {
  int n;
  string s;

  cin >> n;

  while (n--) {
    cin >> s;

    vector<pair<int, int>> v = perse(s);

    for (int i = 0; i < v.size(); ++i) {
      cout << ans(v[i].first, v[i].second);
    }
    cout << endl;
  }
}

C++: #include<stdio.h>
#include<iostream>
#include<utility>
#include<string.h>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define CHMIN(a,b) (a) = min((a),(b))
#define CHMAX(a,b) (a) = max((a),(b))

int main()
{
    char ban[10][10]={{},{'.',',','!','?',' ','#'},{'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','#'}};
    char in[1025]={};
    /*
    REP(i,10)
    {
        REP(j,10)printf("%c ",ban[i][j]);
        printf("\n");
    }
    */
    int a;
    scanf("%d\n",&a);
    while(a-->0)
    {
        REP(i,1025)in[i]='\0';
        scanf("%s\n",in);
        if(in[0]=='\0')return 0;
        char *a=&in[0];
        int num=0;
        int row=0;
        while(*a!='\0')
        {
            if(*a=='0')
            {
                if(ban[row][num]!='\0')printf("%c",ban[row][num]);
                row=0;
                num=0;
            }
            else if(row==*a-'0')
            {
                num++;
                if(ban[row][num]=='#')num=0;
            }
            else if(row!=*a-'0')
            {
                row=*a-'0';
                num=0;
            }
            a++;
        }
        if(ban[row][num]!='\0')printf("%c",ban[row][num]);
        printf("\n");
    }
    return 0;
}

C++: #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 30;

string button[10];

int main(void){
	button[1]=".,!? ";
	button[2]="abc";
	button[3]="def";
	button[4]="ghi";
	button[5]="jkl";
	button[6]="mno";
	button[7]="pqrs";
	button[8]="tuv";
	button[9]="wxyz";
	int t;
	cin >> t;
	rep(i,t){
		string in;
		cin >> in;
		int n=in.size();
		int cur=0,num=0;
		string ans="";
		rep(i,n){
			int tmp=in[i]-'0';
			if(tmp){
 				cur=tmp;
				num++;
			}else{
				if(cur){
					int p=button[cur].size();
					ans+=button[cur][(num-1)%p];
				}
				cur=0;
				num=0;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

using std::cin;
using std::cout;
using std::endl;

char keitai[][6] =
{
	".,!? ",	
	"abc",
	"def",
	"ghi",
	"jkl",
	"mno",
	"pqrs",
	"tuv",
	"wxyz"
	};

char out_keitai(int num, int count) {
	if (num == 1) {
		if (count%5 != 0) {
			return keitai[num-1][(count%5)-1];
		}else {
			return keitai[num-1][4];
		}
	}else if (num == 7 || num == 9) {
		if (count%4 != 0) {
			return keitai[num-1][(count%4)-1];
		}else {
			return keitai[num-1][3];
		}
	}else {
		if (count%3 != 0) {
			return keitai[num-1][(count%3)-1];
		}else {
			return keitai[num-1][2];
		}
	}
}
int main(void) {
	int n;
	char inp;
	std::string str;

	cin >> n;
	cin.ignore(2);

	for (int i = 0; i < n; i++) {
		getline(cin, str);
		int num;
		int count = 0;
		for (int j = 0; j < str.length()-1; j++) {
			std::string dstr;
			dstr = str.substr(j,1);
			num = atoi(dstr.c_str());
			if (num != 0) {
				count++;
				int seq = 1;
				int next_num;
				while (seq) {
					dstr = str.substr(j+1,1);
					next_num = atoi(dstr.c_str());
					if (num == next_num) {
						count++;
						j++;
					}else {
						seq = 0;
						cout << out_keitai(num,count);
						count = 0;
					}
				}	
			}
		}
		cout << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(void){
    char code[][5] = {
        {0,0,0,0,0},
        {'.',',','!','?',' '},
        {97,98,99,0,0},
        {100,101,102,0,0},
        {103,104,105,0,0},
        {106,107,108,0,0},
        {109,110,111,0,0},
        {112,113,114,115,0},
        {116,117,118,0,0},
        {119,120,121,122,0}
    };
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string input;
        cin >> input;
        int num = 0;
        int index = 0;
        for (int j = 0; j < input.length(); ++j) {
            if (input[j] == '0') {
                cout << code[num][index];
                num = 0;
                index = 0;
            } else if (!index && !num) {
                num = input[j] - '0';
            } else {
                while(num) {
                    if (++index == 5) index = 0;
                    if (code[num][index]) break;
                }
            }
        }
        if (i != n - 1)
            cout << endl;
    }
    return 0;
}