标题:[求助]c++统计英文字母的使用频率的程序
只看楼主
huang254
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-6-26
 问题点数:0 回复次数:5 
[求助]c++统计英文字母的使用频率的程序
1. 课题功能描述
本程序的功能,就是要统计英文字母的使用频率。
2. 问题详细描述
为统计英文字母的使用频率,输入一个不包括空格的由英文字母组成的字符串,长度不超过200个字符。统计26个英文字母的使用频率,不区分大小写。最后按使用频率从大到小输出字母(小写字母)和使用频率(出现的次数)。
搜索更多相关主题的帖子: 频率 字母 英文 统计 
2007-06-26 17:45
huang254
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-6-26
得分:0 

大哥大姐们帮帮忙阿 谢谢 小弟不胜感激

2007-06-26 17:46
aipb2007
Rank: 8Rank: 8
来 自:CQU
等 级:贵宾
威 望:40
帖 子:2879
专家分:7
注 册:2007-3-18
得分:0 
简单,自己先想想!

提示:处理字符串
用map容器
………………

Fight  to win  or  die...
2007-06-26 17:48
aipb2007
Rank: 8Rank: 8
来 自:CQU
等 级:贵宾
威 望:40
帖 子:2879
专家分:7
注 册:2007-3-18
得分:0 
吃饭去罗!

Fight  to win  or  die...
2007-06-26 17:48
aipb2007
Rank: 8Rank: 8
来 自:CQU
等 级:贵宾
威 望:40
帖 子:2879
专家分:7
注 册:2007-3-18
得分:0 
[CODE]#include <iostream>
#include <string>

using namespace std;

int main(int argc, char *argv[])
{
//select the letters of input the store them in a string
char word;
string str;
while ((word = cin.get()) != '\n'){
if (isalpha(word)){
word = tolower(word);
str += word;
}
}
//insertion sort for the string
for (int i = 1;i < str.size();++i){
if (str[i] < str[i-1]){
char temp = str[i];
int j = i;
do{
str[j] = str[j-1];
--j;
}
while (j > 0 && temp < str[j-1]);
str[j] = temp;
}
}
if (str.empty()){
cerr << "no letter in your input" << endl;
system("pause");
return EXIT_FAILURE;
}
cout << str << endl;
//count the letter times
int pos = 0;
while (true){
char key = str[pos];
int mark = str.find_first_not_of(key,pos);
if (mark == string::npos){
cout << key << "\t\t" << str.size() - pos << endl;
break;
}
int length = mark - pos;
cout << key << "\t\t" << length << endl;
pos = mark;
}
system("PAUSE");
return EXIT_SUCCESS;
}

[/CODE]

不知道符合要求不
N久前写的,可以接受任何形式的输入,回车键结束。

Fight  to win  or  die...
2007-06-26 19:52
野比
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:24
帖 子:1627
专家分:516
注 册:2007-5-24
得分:0 
aipb兄.. 太包办了吧... 提示一下就好了...

女侠,约吗?
2007-06-26 20:06



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-150530-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.076634 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved