首页 > 代码库 > usaco-crypt1-pass

usaco-crypt1-pass

这个想了半天,终于过了:

/*ID: qq104801LANG: C++TASK: crypt1*/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <assert.h>void debug_dummy(){    return;}int n;int d[10];int numlen(int x){        int l=1;    while(x/10)    {        l++;        x/=10;    }    //printf("%d %d\n",x,l);    return l;}bool iscrypt(int x,int m){       while(m--)    {        if(!d[x%10] || x==0)            return false;        x/=10;            }     if (x!=0)return false;       return true;}bool check(int a,int b){    int p,q;    p=a*(b/10);    q=a*(b%10);    if (!iscrypt(a,3) || !iscrypt(b,2) || !iscrypt(a*b,4))        return false;    if (!iscrypt(p,3) || !iscrypt(q,3) )        return false;    return true;}void test(){    int sum=0;    FILE *fin = fopen ("crypt1.in", "r");    FILE *fout = fopen ("crypt1.out", "w");     fscanf(fin,"%d",&n);    for(int i=0;i<10;i++)        d[i]=0;    for(int i=0;i<n;i++)    {        int t;        fscanf(fin,"%d",&t);        d[t]=1;        //printf("%d %d\n",t,d[t]);            }    for(int i=100;i<1000;i++)        for(int j=10;j<100;j++)        {            if ((i==222) && (j==22))                debug_dummy();            if (check(i,j))            {                sum++;                //printf("%d*%d=%d ==>%d   p1:%d p2:%d\n",i,j,i*j,i*(j%10)+i*(j/10)*10,i*(j%10),i*(j/10));            }        }    //printf("sum:%d\n",sum);    fprintf(fout,"%d\n",sum);    fclose(fin);    fclose(fout);}main () {        test();        exit (0);}

测试用例:

USER: ll tom [qq104801]TASK: crypt1LANG: C++Compiling...Compile: OKExecuting...   Test 1: TEST OK [0.011 secs, 3500 KB]   Test 2: TEST OK [0.008 secs, 3500 KB]   Test 3: TEST OK [0.008 secs, 3500 KB]   Test 4: TEST OK [0.011 secs, 3500 KB]   Test 5: TEST OK [0.005 secs, 3500 KB]   Test 6: TEST OK [0.003 secs, 3500 KB]   Test 7: TEST OK [0.014 secs, 3500 KB]All tests OK.Your program (‘crypt1‘) produced all correct answers! This is your submission #4 for this problem. Congratulations!Here are the test data inputs:------- test 1 ----52 3 4 6 8------- test 2 ----42 3 5 7------- test 3 ----11------- test 4 ----74 1 2 5 6 7 3------- test 5 ----89 1 7 3 5 4 6 8------- test 6 ----61 2 3 5 7 9------- test 7 ----91 2 3 4 5 6 7 8 9Keep up the good work!Thanks for your submission!

 

usaco-crypt1-pass