⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 words_count_1.cpp

📁 A group of word-analysis examples for C++/STL novices
💻 CPP
字号:
/*
*  Description:
*
*    Report the amount of the defferent words in your input.
*
*  History:
*
*    Initial version created by Royal, Mar. 2004.
*
*  Notes:
*
*    This code has been written to conform to standard C++ and STL. It has been
*    compiled successfully using GNU C++ 3.2, Borland C++ 5.5, and Visual C++ 7.0.
*/

#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef vector<string>::size_type vec_sz;

bool output_already(const string& word, const vector<string>& output_words);

int main()
{
    string word;
    vector<string> words;
    vector<string> output_words;
    
    cout << "Please input words:";
    while(cin >> word) words.push_back(word);
    
    const vec_sz words_size = words.size();
    for(vec_sz i = 0; i < words_size; ++i)
    {
        if (output_already(words[i], output_words)) continue;
              
        int count = 0;
        for(vec_sz j = 0; j < words_size; ++j)
            if(words[i] == words[j]) ++count;

        cout << "There are/is " << count << " \"" << words[i] << "\" in your input." << endl;
        output_words.push_back(words[i]);
    }
}

bool output_already(const string& word, const vector<string>& output_words)
{
    vec_sz size = output_words.size();
    for(vec_sz i = 0; i < size; ++i)
        if(word == output_words[i]) return true;
    return false;
}  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -