【水题】USACO Name That Number

进入USACO要注册才能看题: http://train.usaco.org/usacogate

题目:【翻译版、是别处的网站】http://www.wzoi.org/usaco/11%5C206.asp

SAMPLE INPUT (file namenum.in)
4734

SAMPLE OUTPUT (file namenum.out)
GREG


又被水题虐了!


/*
ID: 1006100071
PROG: namenum
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <set>
//#include <map>
#include <queue>
#include <utility>
#include <iomanip>
#include <stack>
#include <list>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <ctype.h>
using namespace std;

struct str{
	char num[30], origin[30];
}x[5005];

int main()
{
	int k = 0, len, i;
	bool flag = false;
	char s[30], map[30] = {"222333444555666707788899900"}; //之前没把无映射字母设置为0,错2次
	freopen ("namenum.in", "r", stdin);
	freopen ("namenum.out", "w", stdout);
	fstream fin ("dict.txt", ios::in);
	while (fin.getline (x[k].origin, 25))
	{
		len = strlen (x[k].origin);
		for (i = 0; i < len; i++)
			x[k].num[i] = map[x[k].origin[i]-'A'];
		x[k].num[len] = 0;
		k++;
	}
	scanf ("%s", s);
	for (i = 0; i < k; i++)
		if (!strcmp (s, x[i].num))
			printf ("%s\n", x[i].origin), flag = true;
	if (!flag)
		puts ("NONE");   //一开始竟然漏掉这句!错一次!
	return 0;
}

你可能感兴趣的:(C++,c,算法,编程语言,ACM)