• usaco-namenum-pass


    呵呵,这个,要转换一下思维,不能被题所导引,感觉代码有点丑:

    /*
    ID: qq104801
    LANG: C++
    TASK: namenum
    */
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <assert.h>
    
    /* for debug only:counter
    */
    void debug_dummy(void)
    {
        return;
    }
    
    typedef struct _dict{
        int n;
        char x[5001][13];
    }dict;
    dict d;
    
    char cc[26]={'2','2','2',
        '3','3','3','4','4','4',
        '5','5','5','6','6','6',
        '7','0','7','7','8','8','8',
        '9','9','9','0'};  
    
    char s[13],t[13];
    
    void initdict(FILE* ff)
    {
        FILE *f=fopen("dict.txt","r");
        int i=0;
        int l=strlen(s);
        int k=0;
        while(fscanf(f,"%s",&d.x[i])!=EOF)
        {
            if (l==strlen(d.x[i]))
            {
                int f=1;
                int j=0;
                while(j<l)
                {
                    if ((d.x[i][j]>='A') && (d.x[i][j]<='Z') && (cc[d.x[i][j]-'A']==s[j]));
                        else
                        {
                            f=0;                
                            break;
                        }
                    j++;
                }
                if (f)
                {                
                    fprintf(ff,"%s
    ",d.x[i]);
                    k++;
                }
            }                
            i++;
        }
        if(!k)
            fprintf(ff,"NONE
    ");
        fclose(f);
        d.n=--i;    
    }
    
    main () {    
        FILE *fin = fopen ("namenum.in", "r");
        FILE *fout = fopen ("namenum.out", "w"); 
        fscanf(fin,"%s",&s);
        initdict(fout);   
        
        fclose(fin);
        fclose(fout);
        exit (0);
    }

    测试数据:

    USER: ll tom [qq104801]
    TASK: namenum
    LANG: C++
    
    Compiling...
    Compile: OK
    
    Executing...
       Test 1: TEST OK [0.008 secs, 3556 KB]
       Test 2: TEST OK [0.016 secs, 3556 KB]
       Test 3: TEST OK [0.019 secs, 3556 KB]
       Test 4: TEST OK [0.014 secs, 3556 KB]
       Test 5: TEST OK [0.014 secs, 3556 KB]
       Test 6: TEST OK [0.008 secs, 3556 KB]
       Test 7: TEST OK [0.011 secs, 3556 KB]
       Test 8: TEST OK [0.005 secs, 3556 KB]
       Test 9: TEST OK [0.014 secs, 3556 KB]
       Test 10: TEST OK [0.005 secs, 3556 KB]
       Test 11: TEST OK [0.011 secs, 3556 KB]
       Test 12: TEST OK [0.014 secs, 3556 KB]
       Test 13: TEST OK [0.008 secs, 3556 KB]
       Test 14: TEST OK [0.005 secs, 3556 KB]
       Test 15: TEST OK [0.014 secs, 3556 KB]
    
    All tests OK.
    
    Your program ('namenum') produced all correct answers! This is your submission #6 for this problem. Congratulations!
    
    Here are the test data inputs:
    
    ------- test 1 ----
    4734
    ------- test 2 ----
    234643
    ------- test 3 ----
    5747867437
    ------- test 4 ----
    223
    ------- test 5 ----
    532
    ------- test 6 ----
    546
    ------- test 7 ----
    53662
    ------- test 8 ----
    5455426
    ------- test 9 ----
    26678268463
    ------- test 10 ----
    463373633623
    ------- test 11 ----
    282742662
    ------- test 12 ----
    463373633623
    ------- test 13 ----
    2336
    ------- test 14 ----
    5264
    ------- test 15 ----
    426
    
    Keep up the good work!
    Thanks for your submission!
    /***********************************************

    看书看原版,原汁原味。

    不会英文?没关系,硬着头皮看下去慢慢熟练,才会有真正收获。

    没有原书,也要网上找PDF来看。

    网上的原版资料多了去了,下载东西也到原始下载点去看看。

    你会知其所以然,呵呵。

    ***********************************************/

  • 相关阅读:
    唯有坚持方能成功
    Java程序猿,你为什么要关注Scala
    HDU 2871 Memory Control(线段树)
    SQL 合并两个结果集 一个倒序,一个正序
    Charm Bracelet(poj3624)(01背包)
    Dijkstra算法,求单源最短路径(包括路径)
    aix平台安装10.2.0.5的CRS时遇到的bug
    Java语言基础系列之1--用IDEA编写HelloWorld
    UVA 10986 Sending email SPFA
    NumberProgressBar开源项目学习
  • 原文地址:https://www.cnblogs.com/dpblue/p/3945794.html
Copyright © 2020-2023  润新知