forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10745.cpp
96 lines (94 loc) · 1.31 KB
/
10745.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
#include <bits/stdc++.h>
using namespace std;
/*
10745
Dominant String
*/
#define MAXN 15002
struct ss
{
int len;
int fre[27];
char dominant;
} word[MAXN];
char W[MAXN][12];
char Rec[MAXN][12];
int total, rec;
int com(const void *a, const void *b)
{
return strcmp((char *)a, (char *)b);
}
int Dominant(int p, int q)
{
int i, j;
for (i = 0; i < W[q][i]; i++)
{
j = W[q][i] - 'a';
if (word[p].fre[j] < word[q].fre[j])
{
return 0;
}
}
return 1;
}
void Cal()
{
int i, j, k, x = 0;
qsort(W, total, sizeof(W[0]), com);
for (i = 0; i < total; i++)
{
word[i].len = strlen(W[i]);
for (j = 0; W[i][j]; j++)
{
k = W[i][j] - 'a';
word[i].fre[k]++;
}
}
for (i = 0; i + 1 < total; i++)
{
if (word[i].dominant == 1)
{
continue;
}
for (j = i + 1; j < total; j++)
{
if (word[j].dominant == 1)
{
continue;
}
if (word[i].len > word[j].len)
{
if (Dominant(i, j))
{
word[j].dominant = 1;
}
}
else if (word[i].len < word[j].len)
{
if (Dominant(j, i))
{
word[i].dominant = 1;
if (word[i].len == word[j].len)
{
word[j].dominant = 1;
}
}
}
}
}
for (i = 0; i < total; i++)
if (word[i].dominant == 0)
{
printf("%s\n", W[i]);
}
}
int main()
{
total = 0;
while (gets(W[total]))
{
total++;
}
Cal();
return 0;
}