summaryrefslogtreecommitdiff
path: root/1.3/namenum.c
blob: dac1f4442f1e225c7b0bb01579d6141e63ba2644 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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;
}