1
#include <cstdio>
2
#include <cstring>
3
#include <algorithm>
4
using namespace std;
5
6
const int SIZE = 30001;
7
const int LEN = 30;
8
9
//用來找出哪些同類
10
struct WORD
11

{
12
char src[LEN];
13
char after[LEN];
14
}word[SIZE];
15
16
//用來找出數目最大的五個
17
struct GROUP
18

{
19
char fst[LEN];
20
int size;
21
int start;
22
}group[SIZE];
23
24
bool cmp(const WORD& a, const WORD& b )
25

{
26
if ( strcmp(a.after, b.after) != 0 )
27
return ( strcmp(a.after, b.after) < 0 );
28
return (strcmp(a.src, b.src) <= 0 );
29
}
30
31
bool cmpGP(const GROUP& a, const GROUP& b)
32

{
33
if ( a.size != b.size )
34
return (a.size > b.size);
35
else
36
return (strcmp(a.fst, b.fst) <= 0);
37
}
38
39
int main()
40

{
41
// freopen("1.txt", "r", stdin);
42
int n, gp, len, i, j, k, p;
43
44
n = 0;
45
46
while ( scanf("%s", word[n].src) != EOF )
47
{
48
strcpy(word[n].after, word[n].src);
49
len = strlen(word[n].after);
50
sort(word[n].after, word[n].after + len);
51
n++;
52
}
53
54
sort(word, word + n, cmp);
55
56
gp = 1;
57
group[0].size = 1;
58
group[0].start = 0;
59
strcpy(group[0].fst, word[0].src);
60
for ( i = 1; i < n; ++i )
61
{
62
if ( strcmp(word[i].after, word[i - 1].after) == 0 )
63
{
64
group[gp - 1].size++;
65
}
66
else
{
67
group[gp].size = 1;
68
group[gp].start = i;
69
strcpy(group[gp].fst, word[i].src);
70
gp++;
71
}
72
}
73
74
sort(group, group + gp, cmpGP);
75
76
for ( i = 0; i < 5; ++i )
77
{
78
printf("Group of size %d:", group[i].size);
79
80
p = group[i].start;
81
for ( j = 0; j < group[i].size; ++j )
82
{
83
for ( k = j - 1; k >= 0; --k )
84
{
85
//相同的單詞只需打印一次
86
if ( strcmp(word[k].src, word[j].src) == 0 )
87
break;
88
}
89
if ( k < 0 || j == 0 )
90
printf(" %s", word[p + j].src);
91
}
92
printf(" .\n");
93
}
94
95
return 0;
96
}

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
