-
Notifications
You must be signed in to change notification settings - Fork 0
/
1224 - DNA Prefix.cpp
executable file
·84 lines (81 loc) · 1.16 KB
/
1224 - DNA Prefix.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
//1224 - DNA Prefix
//By MD.Imam Hossain Johny
//Dept. ICE, NSTU-11 batch
#include<bits/stdc++.h>
using namespace std;
#define SZ 100005
#define MX 100000000
int mx;
struct node
{
int total;
node* next[5];
node()
{
total=1;
for(int i=0;i<4;i++)
{
next[i]=NULL;
}
}
}*root;
int insert(char* str,int len)
{
node* curr=root;
int sum=len;
for(int i=0;i<len;i++)
{
int id;
if(str[i]=='A') id=0;
else if(str[i]=='C') id=1;
else if(str[i]=='G') id=2;
else if(str[i]=='T') id=3;
if(curr->next[id]==NULL)
{
curr->next[id]=new node();
sum=len;
}
else
{
curr->next[id]->total=curr->next[id]->total+1;
sum=(curr->next[id]->total)*(i+1);
if(sum>mx) mx=sum;
}
curr=curr->next[id];
}
if(sum>mx) mx=sum;
return mx;
}
void del(node* curr)
{
for(int i=0;i<4;i++)
{
if(curr->next[i])
{
del(curr->next[i]);
}
}
delete(curr);
}
int main()
{
int x,t;
scanf("%d",&x);
for(t=1;t<=x;t++)
{
root=new node();
int n,len,ans=0;
mx=0;
char str[55];
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%s",str);
len=strlen(str);
ans=insert(str,len);
}
printf("Case %d: %d\n",t,ans);
del(root);
}
return 0;
}