1.2.3 Name That Number

来源:互联网 发布:复旦软件工程硕士 编辑:程序博客网 时间:2024/06/09 13:46

USACO就是特别,此题还要从另外的文件读入辅助信息,看别人的代码看到把stderr都用上...

把字典里的5000个转为数字,再比较输入的那个

 ifstream tin("dict.txt");

是为了输入到string里,因为 如注释那里的freopen只能%s读入,而string只能用流输入

/*ID: email_f1LANG: C++TASK: namenum*/#include <cstdio>#include <cmath>#include <cstring>#include <set>#include <map>#include <stack>#include <queue>#include <vector>#include <iostream>#include <algorithm>#include <fstream>using namespace std;#define ll  long long#define INF 0x7FFFFFFF#define eps 10^(-6)#define Q_CIN ios::sync_with_stdio(false)#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define FOR( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define CLR( a , x ) memset ( a , x , sizeof (a) )#define RE freopen("1.txt","r",stdin);#define WE freopen("1.txt","w",stdout);#define MOD 10009#define NMAX 10002#define min(a,b) ((a)>(b)?(b):(a))#define max(a,b) ((a)<(b)?(b):(a))char d[]= {"22233344455566670778889990"};int main(){    freopen("namenum.in","r",stdin);    freopen("namenum.out","w",stdout);    ifstream tin("dict.txt");    //freopen("dict.txt","r",stderr);    int n,t;    string str,s1,s2;    int flag=0;    cin>>str;    while(tin>>s1)    {        s2="";        REP(i,s1.length())        {            s2+=d[s1[i]-'A'];        }        if(s2==str)        {            cout<<s1<<endl;            flag=1;        }    }    if(!flag)        cout<<"NONE"<<endl;    return 0;}


0 0
原创粉丝点击