From ad4e2420e822b8a115aac6124307b89447578782 Mon Sep 17 00:00:00 2001 From: Iru Cai Date: Mon, 16 Apr 2018 19:06:32 +0800 Subject: 1.2~1.5 --- 1.3/namenum.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 1.3/namenum.c (limited to '1.3/namenum.c') diff --git a/1.3/namenum.c b/1.3/namenum.c new file mode 100644 index 0000000..dac1f44 --- /dev/null +++ b/1.3/namenum.c @@ -0,0 +1,58 @@ +/* +ID: mytbk921 +LANG: C +TASK: namenum +*/ + +#include +#include +#define MAXL 16 + +const char map[]="ABCDEFGHIJKLMNOPRSTUVWXYZ"; //use a 'Z' to map the end + +int mapped(int i,char c) //if mapped,return 0,otherwise return smaller(-1),or bigger(+1) +{ + int j; + if (i>=sizeof(map)/3) //i invalid + return 1; + for (j=i*3;j<(i+1)*3;j++){ + if (map[j]==c) //mapped + return 0; + } + if (c>=map[j]) //c is too big + return 1; + else return -1; +} + +int main() +{ + char target[MAXL],numstr[MAXL]; + FILE *fin=fopen("namenum.in","r"); + FILE *dict=fopen("dict.txt","r"); + FILE *fout=fopen("namenum.out","w"); + int has_answer=0; + fscanf(fin,"%s",numstr); + fclose(fin); + while (fscanf(dict,"%s",target)!=EOF){ + int i; + if (mapped(numstr[0]-'2',target[0])==1) //too big + break; + for (i=0;numstr[i];++i){ + if (mapped(numstr[i]-'2',target[i])!=0) + break; + } + if (numstr[i]||target[i]) //not matched + continue; + else{ + has_answer=1; + fprintf(fout,"%s\n",target); + } + } + if (!has_answer) + fprintf(fout,"NONE\n"); + + fclose(dict); + fclose(fout); + return 0; +} + -- cgit v1.2.3