summaryrefslogtreecommitdiff
path: root/1.3/namenum.c
diff options
context:
space:
mode:
authorIru Cai <mytbk920423@gmail.com>2018-04-16 19:06:32 +0800
committerIru Cai <mytbk920423@gmail.com>2018-04-16 19:06:32 +0800
commitad4e2420e822b8a115aac6124307b89447578782 (patch)
tree6f4db875081597e2e64dd4221a97bbff25503dcc /1.3/namenum.c
parenta7721767628a51b752ad3a96eb334734241dcd8b (diff)
downloadusaco-ad4e2420e822b8a115aac6124307b89447578782.tar.xz
1.2~1.5
Diffstat (limited to '1.3/namenum.c')
-rw-r--r--1.3/namenum.c58
1 files changed, 58 insertions, 0 deletions
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 <stdio.h>
+#include <string.h>
+#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;
+}
+