0127 - Pocket Pager Input

#include <iostream>
#include <string>
using namespace std;

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

void Slove(string str)	{
	string answer="";
	bool flg=true;

	if (str.length()%2) flg=false;
	for (int i=0; i<str.length(); i+=2)	{
		if (0<=str[i]-'0'-1 && str[i]-'0'-1<6 && 0<=str[i+1]-'0'-1 && str[i+1]-'0'-1<5)	answer += data[str[i+1]-'0'-1][str[i]-'0'-1];
		else	{
			flg=false;
			break;
		}
	}
	(flg)? cout << answer << endl : cout << "NA" << endl;
}

int main(void)	{
	string str;

	while (cin >> str)
		Slove(str);
	return 0;
}

やるだけ問題、色々と汚くなった。