USACO:Name That Number

总感觉写的很挫

/*
ID: Jang Lawrence
PROG: namenum
LANG: C++
*/
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<set>
#include<string>
using namespace std;
char n[13];
char temp[13];
int num;
   set<string> Map;
char dir[][4]={"ABC","DEF","GHI","JKL","MNO","PRS","TUV","WXY"};
void dfs(string t,int k )
{
    if(n[k]=='\0')
    {
        if(Map.find(t)!=Map.end())
        cout<<t<<"\n",num++;
        return ;
    }
    int nn=n[k]-'0';
    for(int i=0;i<3;++i)
    {
        dfs(t+dir[nn-2][i],k+1);
    }
}
int main()
{
    freopen("namenum.in","r",stdin);
    freopen("namenum.out","w",stdout);
   FILE  *fin=fopen("dict.txt","r");
     while(fscanf(fin,"%s",temp)==1)
  {
      string t(temp);
      Map.insert(t);
  }
  scanf("%s",n);
  num=0;
  dfs("",0);
  if(num);
  else
  puts("NONE");
    return 0;
}

你可能感兴趣的:(USACO:Name That Number)