+ -
当前位置:首页 → 问答吧 → 求助:哪位高人帮忙编一下代码用C++

求助:哪位高人帮忙编一下代码用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)输出删除某一字符串后的文章。

作者: nayizhan   发布时间: 2011-12-21

c++但是没用链表;删除某string也没有实现;
( A2 V; `' ^9 i3 p$ a; p明天再改
复制内容到剪贴板
代码:
//#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