查找字符出现次数最多(再看)
来源:互联网 发布:下载定时开关机软件 编辑:程序博客网 时间:2024/06/05 16:18
Time Limit:60MS Memory Limit:65536KB 64bit IO Format:%lld & %llu
Description
给出n(1<= n && n <= 2*10^6)个字符串,每个字符串只包含小写英文字母,且最多有五个。问这n个字符串中出现次数最多的有多少个。
Input
单组输入。第一行输入一个数字n,接下来n行,每行包含一个字符串。
Output
输出一个数字代表答案。
Sample Input
5abaabbwabaz
Sample Output
2
Hint
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <algorithm>using namespace std;struct node{ int flag; node *next[26];};int n,m;int Max=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 *tree,char *b){ int ans; int len = strlen(b); node *p = tree; for(int i = 0;i<len;i++) { ans = b[i]-'a'; if(p->next[ans]==NULL) { p->next[ans] = creat(); } p = p->next[ans]; } p->flag++; if((p->flag) >Max) Max = p->flag;}void freenode( node*tree){ for(int i = 0;i<n;i++) { if(tree->next[i]!=NULL) { freenode(tree->next[i]); } } free(tree);}int main(){ char a[2000000][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",Max); freenode(p); return 0;}
0 0
- 查找字符出现次数最多(再看)
- 查找字符串中出现次数最多的字符
- 查找字符串中出现次数最多的字符
- 查找字符串中出现次数最多的字符
- 查找字符串中出现最多次数的字符及其个数
- js查找字符串中出现次数最多的字符
- 出现次数最多的字符
- 查找字符出现次数
- 题目:JavaScript编程题 查找字符串"sdddrtkjsfkkkasjdddj"中出现次数最多的字符和次数。
- 20171101(查找sdddrtkjsfkkkasjdddj字符串中,出现次数最多的字符和次数。)
- 题目:JavaScript编程题 查找字符串"sdddrtkjsfkkkasjdddj"中出现次数最多的字符和次数。
- 查找出字符串中出现最多的字符及其出现的次数
- 查找一个字符串中出现次处最多的那个字符,并输出出现次数
- 查找出字符串中出现最多的字符及其出现的次数
- 查找出字符串中出现最多的字符及其出现的次数
- 求出现最多的字符及次数
- 字符串中出现次数最多的字符
- 计蒜客-求出现次数最多的字符
- 初识EM algorithm
- 【九度OJ】1015【模拟】【A+B系列2006】
- [POJ 3599] Pumping Lemma [BFS]
- 用javascript实现全选/反选组件
- 基于Hash的查找算法实现
- 查找字符出现次数最多(再看)
- 字符串替换 REPLACE,得到字符的ASCII码
- HBase编程实例
- 数据结构之---树(二)
- uva10201 - Adventures in Moving - Part IV(01背包)
- vs2010 combo box 添加data数据
- 分析javascript中的闭包
- 关于单链表函数操作中return head的意义
- Android菜鸟学习笔记之---用handler更新UI