Gym 100935FA poet ComputerTime
limit:2000MS
Memory Limit:65536KB
64bit IO Format:%i64d & %i64u
Description
Standard Input/output
The ACM team is working on a AI project called (Eih Eye Three) that allows computers to write poems. One of the problems they stumbled upon is finding words with the same suffix. The ACM team constructed a dictionary of words, they was interested only in the longest common suffix, which is, a suffix c Ommon to three or more words in the dictionary ... A suffix is any substring this starts from some arbitrary position in the string and reaches the end of the string. As the ACM team is also preparing for the acm-tcpc2015 contest, they figured that the contestants can help in solving thi s problem. Your task is to write a program, finds a longest common suffix in a dictionary of words. An entry in the dictionary is a word of 中文版 letters only. Small letters is the same as capital letters. You can assume this there is exactly a unique solution for every test case.
Input
The first line of the input contains an integer T, the number of test cases. Each test case starts with a line containing one integer K, then K lines follow, each containing one string "Si" that repr Esents an entry in the dictionary. 0 < T ≤50 | S I|≤100 0 < K ≤1000
Output
For each test case, print on the first line "Case C:" Where ' C ' was the test case number. On the second line should print an integer denoting the length of the longest common suffix and another integer denoti ng How many words has the suffix appeared in.
Sample Input
Input
2
4
Cocochannel
Chrisschannel
Mbcchannel
ControlPanel
5
Superman
Batman
Ironman
Chrissbrown
Mycrown
Output
Case 1:
3 ·
Case 2:
3 3
/* /test Instructions: Find the longest common suffix; simple dictionary tree, look for suffixes greater than or equal to 3, the length of the suffix as large as possible. AC Code:/*
#include "algorithm" #include "iostream" #include "CString" #include "cstdlib" #include "Cstdio" #include "string" # Include "vector" #include "queue" #include "Cmath" using namespace std;typedef long long LL; #define MEMSET (x, y) memset (x, Y, sizeof (x)) #define MEMCPY (x, y) memcpy (x,y,sizeof) #define FK (x) cout<< "[" <<x<< "]\n" struct Trie { int V;int Len; Trie *next[26];} root;struct Ans {int len,num;} ans,t;void init () {ans.len=ans.num=0;t.len=t.num=0;} void Buildtree (char *s) {//FK ("NO"); int Len=strlen (s); Trie *p=&root,*q;for (int i=len-1; i>=0; i--) {int num;//if (!) ( (s[i]<= ' Z ' &&s[i]>= ' A ') | | (s[i]<= ' z ' &&s[i]>= ' a '))) Continue;if (s[i]<= ' z ' &&s[i]>= ' a ') num=s[i]-' a '; else num=s[i]-' a '; if (p->next[num]==null) {q= (Trie *) malloc (sizeof (root)); q->v=1;for (int j=0; j<26; J + +) {q->next[j]=null;} Q->len=p->len+1;p->next[num]=q;p=p->next[num];} else {p=p->next[num];p->v++;} if (p->v >= 3&&p->len >= t.len) {T.LEN=P->len;t.num=p->v;}}} void Deletetrie (Trie *t,int k) {if (t==null) return; for (int i=0; i<26; i++) {if (t->next[i]!=null) {Deletetrie (t-> ; next[i],k+1);}} if (k==0) {for (Int. i=0; i<26; i++) {t->next[i]=null;}} else Free (T); return;} int main () {int T,n;char s[205];scanf ("%d", &t), for (int qq=1; qq<=t; qq++) {scanf ("%d", &n), Init (); for (int i=0 ; i<n; i++) {cin>>s; Buildtree (s); if (T.num>=3&&t.len>=ans.len) {ans=t;}} printf ("Case%d:\n", QQ);p rintf ("%d%d\n", ans.len,ans.num); Trie *p=&root;deletetrie (p,0);} return 0;}
Acm:gym 100935F A poet Computer-dictionary tree