Дан файл целых чисел с диапазоном значений от a до b. Определите, сколько раз встречается каждое значение в файле.
Язык С++.

Ответы

Ответ дал: clinteastwood2
0
//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64

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

mt19937 gen { random_device()() };
uniform_int_distribution<> uid(0, 100); //диапазон от 0..100

int main()
{   
    fstream f("F2.txt");
    int a, b;
    cin >> a >> b;
    for (size_t i = a; i < b; ++i) {
        f << uid(gen) << " ";
    }
    vector<int> v;
    map<int, size_t> m;
    int temp;
    while ( !f.eof() ) {
        f >> temp;
        v.push_back(temp);
    }
    for (auto it = v.begin(); it != v.end(); ++it) {
        m[*it]++;
    }
    for (const auto &i : m) {
        cout << i.first << " = " << i.second << endl;
    }
}
___________________
Пример:
55 13 51 55 55 21 38 59 62 20 62 10 9 55 28 60 28 24 95 7
7 = 1
9 = 1
10 = 1
13 = 1
20 = 1
21 = 1
24 = 1
28 = 2
38 = 1
51 = 1
55 = 4
59 = 1
60 = 1
62 = 2
95 = 1
Ответ дал: angryfukse
0
Спасибо)
Вас заинтересует