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]='\0';
    //printf("%s  len:%d\n",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\n",i);
                    //printf("%d %d %s\n",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\n",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!

 

转载于:https://www.cnblogs.com/dpblue/p/3947062.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值