Advertisement
maxim_shlyahtin

1257

Nov 25th, 2021 (edited)
587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <fstream>
  5. #include <algorithm>
  6.  
  7.  
  8.  
  9. int main()    
  10. {  
  11.     using namespace std;
  12.     int count = 0;
  13.     int k = 0, f = 0, max = 0;
  14.     vector <int> a;
  15.     vector <int> even;
  16.     vector <int> uneven;
  17.     vector <string> v;
  18.     string path = "stat.txt";
  19.     ifstream fin;
  20.     fin.open(path);
  21.  
  22.     if (!fin.is_open())
  23.     {
  24.         cout << "Error!" << endl;
  25.     }
  26.     else
  27.     {
  28.         string str;
  29.         while (!fin.eof())
  30.         {
  31.             getline(fin, str);
  32.             v.push_back(str);
  33.         }
  34.     }
  35.     fin.close();
  36.     for (int i = 0; i < (int)v.size() - 1; i++)
  37.     {  
  38.         try {
  39.             int res = stoi(v[i]);
  40.             a.push_back(res);
  41.         }
  42.         catch (invalid_argument e) {
  43.             cout << "Caught invalid argument exception\n";
  44.             cout << i;
  45.         }
  46.     }
  47.     sort(a.begin(), a.end());
  48.     for (int i = 0; i < (int)a.size(); i++) {
  49.         if (a[i] % 2 == 0)
  50.             even.push_back(a[i]);
  51.         else if (a[i] % 2 == 1)
  52.             uneven.push_back(a[i]);
  53.     }
  54.     for (int i = 0; i < even.size(); i++) {
  55.         for (int j = 0; j < uneven.size(); j++) {
  56.             k = even[i] + uneven[j];
  57.             vector<int>::iterator it = find(uneven.begin(), uneven.end(), k);
  58.             if (it != uneven.end()) {
  59.                 count++;
  60.                 if (max < *it)
  61.                     max = *it;
  62.             }
  63.         }
  64.     }
  65.     cout << count << " " << max;
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement