求助:哪位高人帮忙编一下代码用C++
时间:2011-12-21
来源:互联网
文章编辑:输入一页文字,程序可以统计出文字、数字、空格的个数。 / \0 X9 ^; `; U$ \% Y
静态存储一页文章,每行最多不超过80个字符,共N行;要求(1)分别统计出其中英文字母数和空格数及整篇文章总字数;(2)统计某一字符串在文章中出现的次数,并输出该次数;(3)删除某一子串,并将后面的字符前移。
1 g- ]# u! u8 T+ O( b存储结构使用线性表,分别用几个子函数实现相应的功能; 4 G4 R' c5 F6 q' B( R
输入数据的形式和范围:可以输入大写、小写的英文字母、任何数字及标点符号。
7 P3 ^! o) b6 X: l8 |+ M! I输出形式:(1)分行输出用户输入的各行字符;(2)分4行输出"全部字母数"、"数字个数"、"空格个数"、"文章总字数"(3)输出删除某一字符串后的文章。
静态存储一页文章,每行最多不超过80个字符,共N行;要求(1)分别统计出其中英文字母数和空格数及整篇文章总字数;(2)统计某一字符串在文章中出现的次数,并输出该次数;(3)删除某一子串,并将后面的字符前移。
1 g- ]# u! u8 T+ O( b存储结构使用线性表,分别用几个子函数实现相应的功能; 4 G4 R' c5 F6 q' B( R
输入数据的形式和范围:可以输入大写、小写的英文字母、任何数字及标点符号。
7 P3 ^! o) b6 X: l8 |+ M! I输出形式:(1)分行输出用户输入的各行字符;(2)分4行输出"全部字母数"、"数字个数"、"空格个数"、"文章总字数"(3)输出删除某一字符串后的文章。
作者: nayizhan 发布时间: 2011-12-21
c++但是没用链表;删除某string也没有实现;
( A2 V; `' ^9 i3 p$ a; p明天再改
( A2 V; `' ^9 i3 p$ a; p明天再改
复制内容到剪贴板
#include<fstream>
#include<string>
#include<algorithm>
#include<iostream>
#include<sstream>
#include<vector>
#include<map>
using namespace std;
int main()
{
ifstream file;
file.open("a.txt");
string line,word;
vector<string> line_of_txt;
map<string,int> word_of_line;
int alpha=0,digit=0,space =0,all=0;
while(getline(file,line))
{
line_of_txt.push_back(line);
istringstream aline(line);
while(aline>>word)
word_of_line[word]++;
for(string::iterator iter=line.begin();iter!=line.end();iter++)
{
if(*iter=' ')space++;
else if(isalpha(*iter))alpha++;
else if(isdigit(*iter))digit++;
all++;
}
}
cout<<"the line of txt is:"<<endl;
for(vector<string>::iterator iter=line_of_txt.begin();iter!=line_of_txt.end();iter++)
cout<<*iter<<endl;
cout<<"alpha:"<<alpha<<endl<<"digit:"<<digit<<endl<<"all:"<<all<<endl<<"space:"<<space<<endl;
cout<<"please enter the word need look"<<endl;
string s;
cin>>s;
cout<<word_of_line[word]<<" words"<<endl;
string exclude;
cout<<"please enter the word need exclude:"<<endl;
cin>>exclude;
return 0;
}
代码:
//#include"alist.h"#include<fstream>
#include<string>
#include<algorithm>
#include<iostream>
#include<sstream>
#include<vector>
#include<map>
using namespace std;
int main()
{
ifstream file;
file.open("a.txt");
string line,word;
vector<string> line_of_txt;
map<string,int> word_of_line;
int alpha=0,digit=0,space =0,all=0;
while(getline(file,line))
{
line_of_txt.push_back(line);
istringstream aline(line);
while(aline>>word)
word_of_line[word]++;
for(string::iterator iter=line.begin();iter!=line.end();iter++)
{
if(*iter=' ')space++;
else if(isalpha(*iter))alpha++;
else if(isdigit(*iter))digit++;
all++;
}
}
cout<<"the line of txt is:"<<endl;
for(vector<string>::iterator iter=line_of_txt.begin();iter!=line_of_txt.end();iter++)
cout<<*iter<<endl;
cout<<"alpha:"<<alpha<<endl<<"digit:"<<digit<<endl<<"all:"<<all<<endl<<"space:"<<space<<endl;
cout<<"please enter the word need look"<<endl;
string s;
cin>>s;
cout<<word_of_line[word]<<" words"<<endl;
string exclude;
cout<<"please enter the word need exclude:"<<endl;
cin>>exclude;
return 0;
}
作者: 月夜幻影 发布时间: 2011-12-22
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28