Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <map>
- #include <string>
- #include <sstream>
- int main()
- {
- std::map<int, int> schools_count;
- int max_count = 0;
- std::ifstream fin("input.txt");
- if (fin.is_open())
- {
- std::string str;
- while (getline(fin, str))
- {
- //считываем в холостую имя и фамилию (Этот кусок я спионерил
- //чтобы вложиться во время)
- const auto name = str.find(' ');
- const auto surname = str.find(' ', name + 1);
- const auto schoolNumberSize = str[surname + 2] == ' ' ? 1 : 2;
- int scool_num = std::stoi(str.substr(surname + 1, schoolNumberSize));
- if (schools_count.find(scool_num) == schools_count.cend())
- schools_count[scool_num] == 0;
- else
- {
- schools_count[scool_num] += 1;
- if (schools_count[scool_num] > max_count)
- max_count = schools_count[scool_num];
- }
- }
- }
- fin.close();
- std::ofstream fout("output.txt");
- for (std::map<int,int>::const_iterator it = schools_count.cbegin(); it != schools_count.cend(); it++)
- {
- if (it->second == max_count)
- fout << it->first << " ";
- }
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement