-1

ユーザーからコンテンツを読み取り、ベクトル配列の出現値を含む各単語を取得しています。

プログラム実行ベクトルがユーザーからプロセスに新しいコンテンツを取得するたびに。以下の例では、文字列を静的に取得しています。

私が欲しい

  1. vector に追加されて永続化される単語のセット。つまり、ユーザーが新しいコンテンツを入力したときの 2 回目の繰り返しです。カウント値を持つ新しい単語は、以前のベクトル値とマージする必要があります。そしてそのたびに、それは成長し続けます。ベクトルのスコープは明らかにメイン関数であるため、プログラムが実行されるたびにフラッシュされます。ベクター内のコンテンツを動的に追加して永続化できるように、誰かが私にアイデアを提案できますか?

  2. 前のベクター コンテンツには、カウント値 5 の「モバイル」という単語があります。また、ユーザー コンテンツにも、カウント 3 の「モバイル」があります。その後、最終的なベクターには、カウント 8 の「モバイル」という単語が含まれている必要があります。

  3. ベクトルの内容をアルファベット順に並べ替える C++ クラスまたはメソッドはありますか?

l

int main()
{
    typedef std::unordered_map < std::string, int >occurrences;
    occurrences s1;
    std::string s = "one two two three one one two";
    std::string input = "one,two; three";
    std::istringstream iss(std::move(s));
    std::vector < std::string > most;
    int max_count = 0;
    while (iss >> s) {
    int tmp = ++s1[s];
    if (tmp == max_count) {
        most.push_back(s);
    } else if (tmp > max_count) {
        max_count = tmp;
        most.clear();
        most.push_back(s);
    }
    }

    //Print each word with it's occurance

    //I want vector most to be declared and used in such a way that below coming value should remain persistent each time user perform action
    for (occurrences::const_iterator it = s1.cbegin(); it != s1.cend(); ++it)
    std::cout << it->first << " : " << it->second << std::endl;

    //Print the words with max occurance
    std::cout << std::endl << "Maximum Occurrences" << std::endl;
    for (std::vector < std::string >::const_iterator it = most.cbegin(); it != most.cend(); ++it)
    std::cout << *it << std::endl;
    return 0;
}
4

1 に答える 1