zoukankan      html  css  js  c++  java
  • usaco-dualpal-pass

    呵呵,这两道题相差不大:

    /*
    ID: qq104801
    LANG: C++
    TASK: dualpal
    */
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <assert.h>
    
    /* for debug only:counter
    */
    void debug_dummy(void)
    {
        return;
    }
    
    int n,s;
    char x[32];
    char num[]={'0','1','2','3','4','5','6','7','8','9'};
    
    void xnum(int a,int b)
    {
        int i=0;
        int c=a;
        while(c!=0)
        {
            x[i]=num[c%b];
            c=c/b;
            i++;
        }
        x[i]='';
        //printf("%s  len:%d
    ",x,strlen(x));    
    }
    
    int ispalindromes(char* s)
    {
        int l=strlen(s);
        int f=1;
        for(int i=0;i<(l/2);i++)
        {
            if(s[i]!=s[l-i-1])
            {
                f=0;
                break;
            }
        }
        return f;
    }
    
    void test(FILE* f)
    {
        int count=0,jj;
        int i;
        i=s;
        while(i++)
        {
            jj=0;
            for(int j=2;j<=10;j++)  
            {      
                xnum(i,j);
                if (ispalindromes(x))
                {
                    jj++;
                    if (jj==2)
                    {
                        fprintf(f,"%d
    ",i);
                        //printf("%d %d %s
    ",i,j,x);  
                        count++;
                        if (count>(n-1))
                            return;
                        break;  
                    }
                }
            }
        }
    }
    
    main () {    
        FILE *fin = fopen ("dualpal.in", "r");
        FILE *fout = fopen ("dualpal.out", "w"); 
        fscanf(fin,"%d %d",&n,&s);
        //printf("%d
    ",base);
        test(fout);
        fclose(fin);
        fclose(fout);
        exit (0);
    }

    测试用例:

    USER: ll tom [qq104801]
    TASK: dualpal
    LANG: C++
    
    Compiling...
    Compile: OK
    
    Executing...
       Test 1: TEST OK [0.005 secs, 3496 KB]
       Test 2: TEST OK [0.003 secs, 3496 KB]
       Test 3: TEST OK [0.008 secs, 3496 KB]
       Test 4: TEST OK [0.008 secs, 3496 KB]
       Test 5: TEST OK [0.011 secs, 3496 KB]
       Test 6: TEST OK [0.011 secs, 3496 KB]
       Test 7: TEST OK [0.008 secs, 3496 KB]
    
    All tests OK.
    
    Your program ('dualpal') produced all correct answers! This is your submission #2 for this problem. Congratulations!
    
    Here are the test data inputs:
    
    ------- test 1 ----
    5 1
    ------- test 2 ----
    9 10
    ------- test 3 ----
    15 9900
    ------- test 4 ----
    10 90
    ------- test 5 ----
    12 125
    ------- test 6 ----
    12 1900
    ------- test 7 ----
    8 500
    
    Keep up the good work!
    Thanks for your submission!
    /***********************************************

    看书看原版,原汁原味。

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

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

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

    你会知其所以然,呵呵。

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

  • 相关阅读:
    Elasticsearch 客户端TransportClient vs RestClient
    MySQL(三)——MySQL45题
    MySQL(二)——其他基础功能
    MySQL(一)——CRUD语句
    JVM(十)——类的加载与加载器
    JVM(九)——字节码指令集
    每日总结
    《构建之法》读后感(三)
    《构建之法》读后感(二)
    《构建之法》读后感(一)
  • 原文地址:https://www.cnblogs.com/dpblue/p/3947062.html
Copyright © 2011-2022 走看看