SDUT OJ -2892 A
生活随笔
收集整理的這篇文章主要介紹了
SDUT OJ -2892 A
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
A
Time Limit: 60ms?? Memory limit: 65536K??有疑問?點這里^_^
題目描寫敘述
給出n(1<= n && n <= 2*10^6)個字符串,每一個字符串僅僅包括小寫英文字母。且最多有五個。問這n個字符串中出現次數最多的有多少個。
輸入
單組輸入。第一行輸入一個數字n,接下來n行,每行包括一個字符串。
輸出
輸出一個數字代表答案。演示樣例輸入
5 aba abb w aba z演示樣例輸出
2提示
字段樹,模板題#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> const int N = 20010; using namespace std;struct node{int flag;node *next[26]; }; int n,m,ans = 0; struct node *Creat() {node *p = new node;for(int i = 0;i<26;i++){p->next[i] = NULL;}p->flag = 0;return p; }void INsert(node *root,char *b) {int num;int len = strlen(b);node *p = root;for(int i = 0;i<len;i++){num = b[i]-'a';if(p->next[num]==NULL){p->next[num] = Creat();}p = p->next[num];}p->flag++;if(p->flag > ans)ans = p->flag; }void FREE(struct node*root) {for(int i = 0;i<n;i++){if(root->next[i]!=NULL){FREE(root->next[i]);}}free(root); } int main() {char a[N][50],s[50];node *p;scanf("%d",&m);p = Creat();for(int i = 0;i<m;i++){scanf("%s",s);INsert(p,s);}printf("%d\n",ans);FREE(p);return 0; }/**************************************Result : Accepted Take Memory : 4452K Take Time : 10MS Submit Time : 2014-06-21 16:13:31 **************************************/
總結
以上是生活随笔為你收集整理的SDUT OJ -2892 A的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 运营商在万物互联扮演什么角色?上海联通N
- 下一篇: 如何节约数据中心空间