统计一串字符串中出现次数最多和次多的单词(华为上机考试题)
来源:互联网 发布:淘宝网羽毛球鞋 编辑:程序博客网 时间:2024/05/18 20:52
//统计一串字符串中出现次数最多和次多的单词
#include<stdio.h>
#include<string.h>
#include<iostream>
int compare(const char * st1,const char * st2)
{
if (strcmp(st1,st2)==0)
return 1;
else
return 0;
}
void PickWord(const char* pInPut,char *pOutPut1,char *pOutPut2)
{
char tem[BUFSIZ][40]={'\0'};
const char *p=pInPut;
int j=0;
int i=0;
int l=0;
char *po1=pOutPut1;
char *po2=pOutPut2;
//用二维数组存储单词
while(*p!='\0')
{
if(((*p>='a')&&(*p<='z'))||((*p>='A')&&(*p<='Z'))||(*p=='\''))
{
tem[j][i++]=*p ;
p++;
}
else
{
tem[j][i]='\0';
j++;
p++;
i=0;}
}
int m,n,max1,max2;
int max[BUFSIZ]={0};
//统计每个单词的次数
for (n=0;n<=j;n++)
{
max[n]=0;
for(m=0;m<=j;m++)
{
max[n]+=compare(tem[n],tem[m]);
}
}
//找出最多的单词
max1=0;
max2=0;
for (n=0;n<=j;n++)
{
if (max[n]>max1)
{
max1=max[n];
i=n;
}
}
for (l=0;l<strlen(tem[i]);l++)
{
*pOutPut1++=tem[i][l];
}
*pOutPut1='\0';
//将最多的单词的统计个数置0
for (n=0;n<=j;n++)
{
if ((max[n]==max1)&&compare(tem[n],po1))
max[n]=0;
}
//找出次多的单词
for (n=1;n<=j;n++)
{
if (max[n]>max2)
{
max2=max[n];
i=n;
}
}
for (l=0;l<strlen(tem[i]);l++)
{
*pOutPut2++=tem[i][l];
}
*pOutPut2='\0';
}
void main()
{
const char a[]="I'm so good,and good and good no no no no";
char* b=(char *)malloc(sizeof(char)*40);
char* c=(char *)malloc(sizeof(char)*40);
PickWord(a,b,c);
std::cout<<b<<std::endl;
std::cout<<c<<std::endl;
free(b);
free(c);
}
#include<stdio.h>
#include<string.h>
#include<iostream>
int compare(const char * st1,const char * st2)
{
if (strcmp(st1,st2)==0)
return 1;
else
return 0;
}
void PickWord(const char* pInPut,char *pOutPut1,char *pOutPut2)
{
char tem[BUFSIZ][40]={'\0'};
const char *p=pInPut;
int j=0;
int i=0;
int l=0;
char *po1=pOutPut1;
char *po2=pOutPut2;
//用二维数组存储单词
while(*p!='\0')
{
if(((*p>='a')&&(*p<='z'))||((*p>='A')&&(*p<='Z'))||(*p=='\''))
{
tem[j][i++]=*p ;
p++;
}
else
{
tem[j][i]='\0';
j++;
p++;
i=0;}
}
int m,n,max1,max2;
int max[BUFSIZ]={0};
//统计每个单词的次数
for (n=0;n<=j;n++)
{
max[n]=0;
for(m=0;m<=j;m++)
{
max[n]+=compare(tem[n],tem[m]);
}
}
//找出最多的单词
max1=0;
max2=0;
for (n=0;n<=j;n++)
{
if (max[n]>max1)
{
max1=max[n];
i=n;
}
}
for (l=0;l<strlen(tem[i]);l++)
{
*pOutPut1++=tem[i][l];
}
*pOutPut1='\0';
//将最多的单词的统计个数置0
for (n=0;n<=j;n++)
{
if ((max[n]==max1)&&compare(tem[n],po1))
max[n]=0;
}
//找出次多的单词
for (n=1;n<=j;n++)
{
if (max[n]>max2)
{
max2=max[n];
i=n;
}
}
for (l=0;l<strlen(tem[i]);l++)
{
*pOutPut2++=tem[i][l];
}
*pOutPut2='\0';
}
void main()
{
const char a[]="I'm so good,and good and good no no no no";
char* b=(char *)malloc(sizeof(char)*40);
char* c=(char *)malloc(sizeof(char)*40);
PickWord(a,b,c);
std::cout<<b<<std::endl;
std::cout<<c<<std::endl;
free(b);
free(c);
}
- 统计一串字符串中出现次数最多和次多的单词(华为上机考试题)
- 统计一串字符串中出现次数最多和次多的单词(华为上机考试题)
- 华为:统计一串字符串中出现次数最多和次多的单词(华为上机考试题)
- 统计一串字符串中出现次数最多和次多的单词
- 一串字符串中出现次数最多的单词
- 统计字符串中出现最多的单词和次多的单词
- 转载:统计一串英文中出现次数最多的单词以及次数;
- 华为上机试题(java)找出一个字符串中出现次数最多的字符
- JAVA-统计英文句子中出现次数最多的单词和出现的次数
- java实现找出一串单词中最长的单词和次数最多的单词
- js——统计字符串中每种字符出现的次数,出现次数最多的是? 出现?次
- 统计一串字符串中各个字符出现的次数
- 【python】统计文本中出现最多次的单词
- 统计连续出现次数最多的单词
- 统计单词出现的最多次数(Trie树)
- java统计字符串中每个字符出现的次数并查询出现次数最多的字符和次数
- 统计字符串中出现最多次数的字母
- 统计字符串中出现次数最多的字母并输出
- 死锁的产生、条件、和解锁
- 读十年书,不如读懂这百句话!
- mysql--联合union、连接 left right inner join、视图学习
- 解决重装系统后,QQ2012无法运行的错误...
- apache 配置虚拟主机
- 统计一串字符串中出现次数最多和次多的单词(华为上机考试题)
- 软件推广策划之三国篇
- dedecms标签大全
- 理想和现实
- java设计模式总结
- SPOJ 1557 Can you answer these queries II(GSS2 线段树)
- 若爱 就如桃花般地去爱
- 久其软件面试
- 深入映射文件---hibernate学习笔记