/
Light-oj-1224 .cpp
74 lines (68 loc) · 1.36 KB
/
Light-oj-1224 .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
#include "bits/stdc++.h"
using namespace std;
int res;
struct node{
bool endmark;
int prefixcnt;
node* next[5];
node(){
endmark=false;
prefixcnt=0;
for(int i=0; i<5; i++){
next[i]=NULL;
}
}
};
int check(char ch){
if(ch=='A')return 0;
if(ch=='C')return 1;
if(ch=='G')return 2;
if(ch=='T')return 3;
}
void INSERT(node* root,char* str,int len){
node* curr=root;
for(int i=0; i<len; i++){
int id=check(str[i]);
if(curr->next[id]==NULL){
curr->next[id]=new node();
}
curr=curr->next[id];
++(curr->prefixcnt);
}
curr->endmark=true;
}
int ans_me(node* curr,int num){
for(int i=0; i<5; i++){
if(curr->next[i]){
ans_me(curr->next[i],num+1);
}
}
res=max(res,curr->prefixcnt*num);
}
void del(node* curr){
for(int i=0; i<5; i++){
if(curr->next[i]){
del(curr->next[i]);
}
}
delete(curr);
}
int main(){
int t,cs=1;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
node* root=new node();
while(n--){
char str[1110];
scanf("%s",&str);
INSERT(root,str,strlen(str));
}
res=0;
ans_me(root,0);
printf("Case %d: %d\n",cs++,res);
del(root);
}
return 0;
}