zoukankan      html  css  js  c++  java
  • USACO 1.3 Name That Number【暴搜】

    裸的穷举搜索。

    研究了好久怎么输入$dict.txt$,$USACO$好像对$freopen$的顺序还有要求?

     1 /*
     2 ID: Starry21
     3 LANG: C++
     4 TASK: namenum                 
     5 */
     6 #include<iostream>
     7 #include<string>
     8 #include<cstdio>
     9 #include<cstring>
    10 #include<map>
    11 #include<algorithm>
    12 using namespace std;
    13 #define N 4617
    14 map<string,bool> vis;
    15 char a[30];
    16 string s[30];
    17 int len;
    18 bool f=0;
    19 void dfs(int i,string n)
    20 {
    21     if(i>len)
    22     {
    23         //cout<<n<<endl;
    24         if(vis[n])
    25         {
    26             f=1;
    27             cout<<n<<endl;
    28         }
    29         return ;
    30     }
    31     int t=a[i]-'0';
    32     for(int k=0;k<=2;k++)
    33         dfs(i+1,n+s[t][k]);
    34 }
    35 int main() 
    36 {
    37     freopen("namenum.in","r",stdin);
    38     freopen("namenum.out","w",stdout);
    39     s[2]="ABC",s[3]="DEF",s[4]="GHI",s[5]="JKL";
    40     s[6]="MNO",s[7]="PRS",s[8]="TUV",s[9]="WXY";
    41     scanf("%s",a+1);
    42     string t;
    43     freopen("dict.txt","r",stdin);
    44     for(int i=1;i<=N;i++)
    45     {
    46         cin>>t;
    47         vis[t]=1;
    48     }
    49     len=strlen(a+1);
    50     //printf("%d
    ",len);
    51     dfs(1,"");
    52     if(f==0) puts("NONE");
    53     return 0;
    54 }
  • 相关阅读:
    try catch finally中return的执行顺序
    多线程和同步
    orecle常用函数
    java如何调用接口 2
    orecle 函数
    ==和equals在比较字符串时候的区别
    orecle触发器
    java实现同步的方法
    java如何调用接口
    SMM+maven下的log4j配置打印sql
  • 原文地址:https://www.cnblogs.com/lyttt/p/11918637.html
Copyright © 2011-2022 走看看