usaco 1.2.3 name that number

我一定是和文件有仇是吧一定是的。。下一道题回文那个难得做的比较顺(只是比较。。囧- -)而且本机上测得没什么问题,以为一定能一次ac了,结果输出文件的stdout手贱写成了stdin。。。。不过至少是过了,可是这题到底是为毛啊本机上都不行,说是什么文件不可读balabala。。。T-T~~

Name That Number

Among the large Wisconsin cattle ranchers, it is customary to brand cows with serial numbers to please the Accounting Department. The cow hands don't appreciate the advantage of this filing system, though, and wish to call the members of their herd by a pleasing name rather than saying, "C'mon, #4734, get along."

Help the poor cowhands out by writing a program that will translate the brand serial number of a cow into possible names uniquely associated with that serial number. Since the cow hands all have cellular saddle phones these days, use the standard Touch-Tone(R) telephone keypad mapping to get from numbers to letters (except for "Q" and "Z"):

          2: A,B,C     5: J,K,L    8: T,U,V
          3: D,E,F     6: M,N,O    9: W,X,Y
          4: G,H,I     7: P,R,S

Acceptable names for cattle are provided to you in a file named "dict.txt", which contains a list of fewer than 5,000 acceptable cattle names (all letters capitalized). Take a cow's brand number and report which of all the possible words to which that number maps are in the given dictionary which is supplied as dict.txt in the grading environment (and is sorted into ascending order).

For instance, the brand number 4734 produces all the following names:

GPDG GPDH GPDI GPEG GPEH GPEI GPFG GPFH GPFI GRDG GRDH GRDI
GREG GREH GREI GRFG GRFH GRFI GSDG GSDH GSDI GSEG GSEH GSEI
GSFG GSFH GSFI HPDG HPDH HPDI HPEG HPEH HPEI HPFG HPFH HPFI
HRDG HRDH HRDI HREG HREH HREI HRFG HRFH HRFI HSDG HSDH HSDI
HSEG HSEH HSEI HSFG HSFH HSFI IPDG IPDH IPDI IPEG IPEH IPEI
IPFG IPFH IPFI IRDG IRDH IRDI IREG IREH IREI IRFG IRFH IRFI
ISDG ISDH ISDI ISEG ISEH ISEI ISFG ISFH ISFI

As it happens, the only one of these 81 names that is in the list of valid names is "GREG".

Write a program that is given the brand number of a cow and prints all the valid names that can be generated from that brand number or ``NONE'' if there are no valid names. Serial numbers can be as many as a dozen digits long.

PROGRAM NAME: namenum

INPUT FORMAT

A single line with a number from 1 through 12 digits in length.

SAMPLE INPUT (file namenum.in)

4734

OUTPUT FORMAT

A list of valid names that can be generated from the input, one per line, in ascending alphabetical order.

SAMPLE OUTPUT (file namenum.out)

GREG

目前的悲剧代码

/*
ID: wtff0411
PROG: namenum
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
using namespace std;
char  convert[]={'2','2','2','3','3','3','4','4','4','5','5','5','6','6','6','7','1','7','7','8','8','8','9','9','9','1'};
int main()
{
    FILE *in=fopen("dict.txt","r");
    
    //freopen("namenum.in","r",stdin);
    //freopen("namenum.out","w",stdout);
    char input[15];
    int i;
    cin>>input;
    int length=strlen(input);
    string res[100];
    int numres=0;
    char check[15];
    while(fscanf(in,"%s",&check)!=EOF)
    {
        if(strlen(check)!=length)
        continue;
        
        for( i=0;i<length;i++)
        {if(convert[check[i]-'A']!=input[i])
        break;
        }
        if(i==length)
        res[numres++]=check;
    }
    sort(res,res+numres-1);
    for(i=0;i<numres;i++)
    cout<<res[i]<<endl;
    if(numres==0)
    cout<<"NONE"<<endl;
    system("pause");
    return 0;
}

泪流满面不止心有戚戚然啊……


在自己的电脑上依旧不行,貌似根本读不进去数据默……但是无聊提交一次发现居然过了你妹。。(发现自己说话开始像啊通了原来如此)。。果然。。是我打开的方式不对么- -。。。

/*
ID: wtff0411
PROG: namenum
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
using namespace std;
char  convert[]={'2','2','2','3','3','3','4','4','4','5','5','5','6','6','6','7','1','7','7','8','8','8','9','9','9','1'};
int main()
{
    //FILE *in=fopen("dict.txt","r");
    ifstream fin ("dict.txt");
    freopen("namenum.in","r",stdin);
    freopen("namenum.out","w",stdout);
    char input[15];
    int i;
    cin>>input;
    int length=strlen(input);
    string res[100];
    int numres=0;
    char check[15];
    while(fin>>check)
    {
        if(strlen(check)!=length)
        continue;
        //cout<<"m"<<endl;
        for( i=0;i<length;i++)
        {if(convert[check[i]-'A']!=input[i])
        break;
        }
        if(i==length)
        {cout<<check<<endl;
        numres=1;}
    }
    //sort(res,res+numres-1);
    
    if(numres==0)
    cout<<"NONE"<<endl;
    //system("pause");
    return 0;
}

或者是txt的格式问题?好麻烦。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值