这个想了半天,终于过了:
/* ID: qq104801 LANG: 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 ",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 ",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 ",i,j,i*j,i*(j%10)+i*(j/10)*10,i*(j%10),i*(j/10)); } } //printf("sum:%d ",sum); fprintf(fout,"%d ",sum); fclose(fin); fclose(fout); } main () { test(); exit (0); }
测试用例:
USER: ll tom [qq104801] TASK: crypt1 LANG: C++ Compiling... Compile: OK Executing... 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 ---- 5 2 3 4 6 8 ------- test 2 ---- 4 2 3 5 7 ------- test 3 ---- 1 1 ------- test 4 ---- 7 4 1 2 5 6 7 3 ------- test 5 ---- 8 9 1 7 3 5 4 6 8 ------- test 6 ---- 6 1 2 3 5 7 9 ------- test 7 ---- 9 1 2 3 4 5 6 7 8 9 Keep up the good work! Thanks for your submission!