IF_0504 2021-05-23 10:04 采纳率: 66.7%
浏览 51

求大神把C++单文件变成多文件!!!

要求有头文件、main文件、函数源文件!!!

 

代码:

#include<iostream>
#include<string>
#include<fstream>
#include<vector>
#include<algorithm>
#include<sstream>
#include<map>
using namespace std;

int main()
{
    int n = 0;
    ifstream myfile("文本.txt");
    ifstream infile("文本1.txt");
    string str;
    string str1[2000];

//定义比较类
    struct ValueComparator
    {
        bool  operator()(const pair<string, int>& x, const pair<string, int>& y)
        {
            return x.second > y.second;
        }
    } comparator;


    if (!myfile.is_open())
    {
        cout << "Some errors" << endl;
    }
    while (getline(myfile, str))
    {
//把大写字母变成小写字母
        for (int a = 0; a < str.length(); a++)
        {
            if (str[a] >= 'A' && str[a] <= 'Z')
            {
                str[a] = str[a] + 32;
            }
        }
//把文章中的标点符号变成空格
        for (int b = 0; b < str.length(); b++)
        {
            if (ispunct(str[b]))
                str[b] = ' ';
        }
//1.统计单词个数
        stringstream ss(str);
        string s;
        vector<string>wordcount;
        while (getline(ss, s, ' '))
        {
            if (s.length() > 0)
                wordcount.push_back(s);
        }
        map<string, int>m1;
        for (int i = 0; i < wordcount.size(); i++)
        {
            m1[wordcount[i]] += 1;
        }
        map<string, int>::iterator word;
        cout << "单词次数统计:" << endl;
        for (word = m1.begin(); word != m1.end(); word++)
        {
            cout << word->first << "=" << word->second << endl;
        }
        cout << " " << endl;

//2.按词频输出
        // 把 map 里的键和值对存到 vector 里,然后按值排序后输出
        vector<pair<string, int> > pairs;
        for (auto& it : m1)
        {
            pairs.push_back(it);
        }
        sort(pairs.begin(), pairs.end(), comparator);
        cout << "词频降序输出:" << endl;
        for (auto it = pairs.begin(); it != pairs.end(); ++it)
        {
            cout << it->first << "=" << it->second << endl;
        }
        cout << " " << endl;
    }
    
//3.倒序输出
    cout << "倒序输出:" << endl;
    if (!infile.is_open())
    {
        cout << "Some errors" << endl;
    }
    while (getline(infile, str))
    {
        //把文章中的标点符号变成空格
        for (int b = 0; b < (str.length()); b++)
        {
            if (ispunct(str[b]))
                str[b] = ' ';
        }
        //逆置整个文章
        reverse(str.begin(), str.end());
        auto start = str.begin();

        //找空格,逆置每个单词
        while (start != str.end())
        {
            auto end = start;
            while (end != str.end() && *end != ' ')
                end++;
            reverse(start, end);
            if (end == str.end())
            {
                start = end;
            }
            else
            {
                start = end + 1;
            }
        }
        str1[n] = str;
        n++;
    }
    for (int s = n - 1; s >= 0; s--)
        cout << str1[s] << endl;
}

 

 

资源文件:

文本:

Our best estimates show there are over 7 billion people on the planet and 300 billion stars in the Milky Way galaxy. By comparison, the adult human body contains 37 trillion cells. To determine the function and relationship among these cells is a monumental undertaking. Many areas of human health would be impacted if we better understand cellular activity. A problem with this much data is a great match for the Kaggle community.Just as the Human Genome Project mapped the entirety of human DNA, the Human BioMolecular Atlas Program is a major endeavor. Sponsored by the National Institutes of Health , HuBMAP is working to catalyze the development of a framework for mapping the human body at a level of glomeruli functional tissue units for the first time in history. Hoping to become one of the world's largest collaborative biological projects, HuBMAP aims to be an open map of the human body at the cellular level.This competition, "Hacking the Kidney," starts by mapping the human kidney at single cell resolution.

 

文本1:

Our best estimates show thOur best estimates show there are over 7 billion people on the planet and 300 billion stars in the Milky Way galaxy. By comparison, the adult human body contains 37 trillion cells. To determine the function and relationship among these cells is a monumental undertaking. Many areas of human health would be impacted if we better understand cellular activity. A problem with this much data is a great match for the Kaggle community.
Just as the Human Genome Project mapped the entirety of human DNA, the Human BioMolecular Atlas Program is a major endeavor. Sponsored by the National Institutes of Health , HuBMAP is working to catalyze the development of a framework for mapping the human body at a level of glomeruli functional tissue units for the first time in history. Hoping to become one of the world's largest collaborative biological projects, HuBMAP aims to be an open map of the human body at the cellular level.
This competition, "Hacking the Kidney," starts by mapping the human kidney at single cell resolution.

  • 写回答

1条回答 默认 最新

  • Simple-Soft 2021-05-23 12:53
    关注

    这个容易

    评论

报告相同问题?

悬赏问题

  • ¥15 SQLServer怎么录入下标
  • ¥100 无网格伽辽金方法研究裂纹扩展的程序
  • ¥15 错误于library(org.Hs.eg.db): 不存在叫‘org.Hs.eg.db’这个名称的程序包,如何解决?
  • ¥60 求一个图片处理程序,要求将图像大小跟现实生活中的大小按比例联系起来的
  • ¥50 求一位精通京东相关开发的专家
  • ¥100 求懂行的大ge给小di解答下!
  • ¥15 pcl运行在qt msvc2019环境运行效率低于visual studio 2019
  • ¥15 MAUI,Zxing扫码,华为手机没反应。可提高悬赏
  • ¥15 python运行报错 ModuleNotFoundError: No module named 'torch'
  • ¥100 华为手机私有App后台保活