就是给你一串数字, 每个数字可以翻译成三个字母, 有一个奶牛姓名表, 输入一串数字然后求出数字可以表示的姓名看看姓名表里面有没有, 有的话输出来,暴力+二分查找即可:
/* ID: m1500293 LANG: C++ PROG: namenum */ #include <cstdio> #include <cstring> #include <algorithm> using namespace std; char validname[5000][15]; int validnum; void getname() { validnum = 0; FILE *dict = fopen("dict.txt", "r"); while(!feof(dict)) { fscanf(dict, "%s", validname[validnum++]); } } char strr[12][5] = {"000", "000", "ABC", "DEF", "GHI", "JKL", "MNO", "PRS", "TUV", "WXY" }; int check(char str[]) { int res = -1; int l=0, r=validnum-1; while(l <= r) { int mid = (l+r)/2; int tp = strcmp(validname[mid], str); if(tp == 0) { res = mid; break; } else if(tp > 0) r = mid-1; else l = mid + 1; } if(res == -1) return 0; else return 1; } char input[15]; int len; bool flog; void dfs(int dept, char str[]) { //printf("%d ", dept); if(dept == len) { str[dept] = '