include cstdio include cstdlib include conio include cstring class nod

 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
59
60
61
62
63
64
65
66
67
68
#include <cstdio>
#include <cstdlib>
#include <conio.h>
#include <cstring>
class node
{
public:
node *p[10];
node ()
{
for(int i=0;i<10;i++)
p[i]=NULL;
};
};
class bor
{
public:
node *root;
bor()
{
root=new node();
};
void Add(node *&pt,int pos,char *word)
{
int n=word[pos]-'0';
if(pt->p[n]==NULL)
pt->p[n]=new node();
if(pos<strlen(word)-1)
Add(pt->p[n],pos+1,word);
};
void Check(node *&pt,int pos,char *word)
{
int n=word[pos]-'0';
if(pt->p[n]==NULL)
{
printf("N dont exist!\n");
return;
}
if(pos<strlen(word)-1)
Check(pt->p[n],pos+1,word);
if(pos==strlen(word)-1)
printf("N found!\n");
return;
};
};
int main(void)
{
bor Bor;
char buff[21];
FILE *f=fopen("nums.txt","r");
while(fscanf(f,"%s\n",buff)!=EOF) {
printf("%s\n",buff);
Bor.Add(Bor.root,0,buff);
}
printf("N: ");
gets(buff);
Bor.Check(Bor.root,0,buff);
getch();
return 0;
}