统计一串字符串中出现次数最多和次多的单词(华为上机考试题)
来源:互联网 发布:剑三正太帅气捏脸数据 编辑:程序博客网 时间:2024/05/18 18:03
//统计一串字符串中出现次数最多和次多的单词
#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统计字符串中每个字符出现的次数并查询出现次数最多的字符和次数
- 统计字符串中出现最多次数的字母
- 统计字符串中出现次数最多的字母并输出
- 在MFC中使Edit Control自动滚动到最底端
- cSparrowApp类以及IO事件处理
- myeclipse不编译解决方法
- 关于QT的pro文件编写及英文文档
- Struts中the request was rejected because its size (***) exceeds the configured ma
- 统计一串字符串中出现次数最多和次多的单词(华为上机考试题)
- 我看易信
- sftp报Received message too long 1114795883
- 8583报文详细分析
- 统计一个字符串中各个英文单词的出现的频数
- ActivityThread运行框架
- TCP/IP模型
- poj 3974
- POJ 1731 下一个全排列