Advertisement
maxim_shlyahtin

954

Nov 25th, 2021
578
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 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 m = 150, k = 100;
  13.     int sum_k = 0, sum_m = 0;
  14.     vector <int> a;
  15.     vector <string> v;
  16.     string path = "nnn.txt";
  17.     ifstream fin;
  18.     fin.open(path);
  19.  
  20.     if (!fin.is_open())
  21.     {
  22.         cout << "Error!" << endl;
  23.     }
  24.     else
  25.     {
  26.         string str;
  27.         while (!fin.eof())
  28.         {
  29.             getline(fin, str);
  30.             v.push_back(str);
  31.         }
  32.     }
  33.     fin.close();
  34.     for (int i = 0; i < (int)v.size() - 1; i++)
  35.     {  
  36.         try {
  37.             int res = stoi(v[i]);
  38.             a.push_back(res);
  39.         }
  40.         catch (invalid_argument e) {
  41.             cout << "Caught invalid argument exception\n";
  42.             cout << i;
  43.         }
  44.     }
  45.     sort(a.begin(), a.end());
  46.     int i = 0;
  47.     for (i = a.size() - 1; i >= a.size() - k; i--) {
  48.         sum_k += a[i] * 0.2;
  49.     }
  50.     for (i; i >= a.size() - k - m; i--) {
  51.         sum_m += a[i] * 0.1;
  52.     }
  53.     cout << sum_k + sum_m << " " << a[i - 1];
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement