daily pastebin goal
33%
SHARE
TWEET

Untitled

a guest Jul 11th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #include <map>
  4. #include <string>
  5. #include <sstream>
  6.  
  7. int main()
  8. {
  9.     std::map<int, int> schools_count;
  10.     int max_count = 0;
  11.  
  12.     std::ifstream fin("input.txt");
  13.     if (fin.is_open())
  14.     {
  15.         std::string str;
  16.  
  17.         while (getline(fin, str))
  18.         {
  19.  
  20.             //считываем в холостую имя и фамилию (Этот кусок я спионерил
  21.             //чтобы вложиться во время)
  22.             const auto name = str.find(' ');
  23.             const auto surname = str.find(' ', name + 1);
  24.             const auto schoolNumberSize = str[surname + 2] == ' ' ? 1 : 2;
  25.  
  26.  
  27.             int scool_num = std::stoi(str.substr(surname + 1, schoolNumberSize));
  28.  
  29.             if (schools_count.find(scool_num) == schools_count.cend())
  30.                 schools_count[scool_num] == 0;
  31.             else
  32.             {
  33.                 schools_count[scool_num] += 1;
  34.                 if (schools_count[scool_num] > max_count)
  35.                     max_count = schools_count[scool_num];
  36.             }
  37.         }
  38.  
  39.     }
  40.     fin.close();
  41.  
  42.  
  43.     std::ofstream fout("output.txt");
  44.  
  45.     for (std::map<int,int>::const_iterator it = schools_count.cbegin(); it != schools_count.cend(); it++)
  46.     {
  47.         if (it->second == max_count)
  48.             fout << it->first << " ";
  49.     }
  50.  
  51.     fout.close();
  52.  
  53.     return 0;
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top