上午那道被北航改编成了研究生上机题,现在这道被清华改编成了上机题。看来usaco是个好东西~
另外,测试时在结尾多输出了一行字符,居然提交上去也过了,可见后台的JUDGE不是用的linux里的differ函数
/* ID:linyvxi1 TASK:namenum LANG:C++ */ #include <string.h> #include <stdio.h> #include <fstream> char num_map[]={'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 num[20]; char dic_name[20]; using namespace std; bool check() { int i; if(strlen(dic_name)!=strlen(num)) return false; for(i=0;i<strlen(dic_name);i++){ if(num_map[dic_name[i]-'A']!=num[i]) return false; } return true; } int main() { FILE* fin=fopen("namenum.in","r"); FILE* fout=fopen("namenum.out","w"); FILE* dir=fopen("dict.txt","r"); fscanf(fin,"%s",num); int i; bool flag=false; for(i=0;i<5000;i++){ fscanf(dir,"%s",dic_name); if(check()){ flag=true; fprintf(fout,"%s\n",dic_name); } } if(!flag) fprintf(fout,"%s\n","NONE"); }
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