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

Ответы 3

  • Спасибо ;)
    • Автор:

      zaire
    • 6 лет назад
    • 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..100int 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 77 = 19 = 110 = 113 = 120 = 121 = 124 = 128 = 238 = 151 = 155 = 459 = 160 = 162 = 295 = 1
  • Добавить свой ответ

Войти через Google

или

Забыли пароль?

У меня нет аккаунта, я хочу Зарегистрироваться

How much to ban the user?
1 hour 1 day 100 years