-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPOJ1318(AC).cpp
98 lines (85 loc) · 1.32 KB
/
POJ1318(AC).cpp
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <stdio.h>
#include <string.h>
typedef char ElementType;
void InsertionSort(ElementType a[], int n)
{
int i;
int j;
ElementType tmp;
for(i = 1; i < n; i++)
{
tmp = a[i];
for(j = i; j > 0 && tmp < a[j - 1]; j--)
{
a[j] = a[j - 1];
}
a[j] = tmp;
}
}
int main()
{
int i;
int j;
int tmp;
int dictcount;
int indices[200];
int found;
char word[10];
char dict[200][10];
char sorteddict[200][10];
dictcount = 0;
while(1)
{
gets(dict[dictcount]);
if(strcmp(dict[dictcount], "XXXXXX") == 0)
{
break;
}
else
{
strcpy(sorteddict[dictcount], dict[dictcount]);
InsertionSort(sorteddict[dictcount], strlen(sorteddict[dictcount]));
dictcount++;
}
}
for(i = 0; i < dictcount; i++)
{
indices[i] = i;
}
for(i = 1; i < dictcount; i++)
{
tmp = indices[i];
for(j = i; j > 0 && strcmp(dict[tmp], dict[indices[j - 1]]) < 0; j--)
{
indices[j] = indices[j - 1];
}
indices[j] = tmp;
}
while(1)
{
gets(word);
if(strcmp(word, "XXXXXX") == 0)
{
break;
}
InsertionSort(word, strlen(word));
found = 0;
for(i = 0; i < dictcount; i++)
{
if(strcmp(word, sorteddict[indices[i]]) == 0)
{
puts(dict[indices[i]]);
if(found == 0)
{
found = 1;
}
}
}
if(found == 0)
{
puts("NOT A VALID WORD");
}
puts("******");
}
return 0;
}