_takumi

weird24

Mar 31st, 2021 (edited)
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <fstream>
  5. #include <string>
  6. using namespace std;
  7.  
  8. string unique_elements(string s) {
  9.     string res;
  10.     for (size_t i = 0; i < s.size(); i++)
  11.     {
  12.         if (res.find(s[i]) == string::npos) {
  13.             res += s[i];
  14.         }
  15.     }
  16.     sort(begin(res), end(res));
  17.     return res;
  18. }
  19.  
  20. int main() {
  21.     ifstream input("\\\\lit.msu.ru\\Storage\\Students\\!Common\\11 класс ИНФОРМАТИКА\\Файлы для диагностической работы 31.03.2021 ЕГЭ информатика\\24\\24.txt");
  22.     string s, minstr;
  23.     int now = 0, min = INT_MAX;
  24.     while (getline(input, s)) {
  25.         now = count(begin(s), end(s), 'G');
  26.         if (now < min) {
  27.             min = now;
  28.             minstr = s;
  29.         }
  30.     }
  31.     string un = unique_elements(minstr);
  32.     int max = 0;
  33.     char maxch;
  34.     for (size_t i = 0; i < un.size(); i++)
  35.     {
  36.         if (count(begin(minstr), end(minstr), un[i]) >= max) {
  37.             max = count(begin(minstr), end(minstr), un[i]);
  38.             maxch = un[i];
  39.         }
  40.     }
  41.     cout << maxch;
  42.     return 0;
  43. }
Add Comment
Please, Sign In to add comment