Name That Number(模拟)(USACO)

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 ();
    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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值