您的位置:首页 > 其它

Name That Number(模拟)(USACO)

2016-09-16 16:27 330 查看
http://train.usaco.org/usacoprob2?S=namenum&a=wnFTyrFubcM

思考:

1、输入学别人的输入乱搞了一发,至今不知道为什么。

2、由于输入只有一个数据,所以不用预处理,只用针对这个数据处理就好了。

/*
ID: emaguo1
PROG: namenum
LANG: C++11
*/
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <map>
#include <cstdio>
#include <algorithm>

using namespace std;

map<char, char> dial;

void init()
{
dial['A']  ='2';
dial['B'] = '2';
dial['C'] = '2';
dial['D'] = '3';
dial['E'] = '3';
dial['F'] = '3';
dial['G'] = '4';
dial['H'] = '4';
dial['I'] = '4';
dial['J'] = '5';
dial['K'] = '5';
dial['L'] = '5';
dial['M'] = '6';
dial['N'] = '6';
dial['O'] = '6';
dial['P'] = '7';
dial['R'] = '7';
dial['S'] = '7';
dial['T'] = '8';
dial['U'] = '8';
dial['V'] = '8';
dial['W'] = '9';
dial['X'] = '9';
dial['Y'] = '9';
}

char s[13], a[13];

int main() {
freopen("namenum.in","r",stdin);
freopen("namenum.out","w",stdout);
freopen ("dict.txt", "r", stderr);
init ();

a864
cin >> a;
bool flag1 = false;
while (fscanf (stderr, "%s", s) != EOF) {
int l = strlen(s);
if (l != strlen(a)) continue;
bool flag = true;
for (int i = 0; i < l; i++) {
if (!dial.count(s[i])) {
flag = false;
break;
}
if (dial[s[i]] != a[i]) {
flag = false;
break;
}
}
if (flag) {
cout << s << endl;
flag1 = true;
}
}
if (!flag1) cout << "NONE" << endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: