Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <fstream>
- #include <algorithm>
- int main()
- {
- using namespace std;
- int m = 150, k = 100;
- int sum_k = 0, sum_m = 0;
- vector <int> a;
- vector <string> v;
- string path = "nnn.txt";
- ifstream fin;
- fin.open(path);
- if (!fin.is_open())
- {
- cout << "Error!" << endl;
- }
- else
- {
- string str;
- while (!fin.eof())
- {
- getline(fin, str);
- v.push_back(str);
- }
- }
- fin.close();
- for (int i = 0; i < (int)v.size() - 1; i++)
- {
- try {
- int res = stoi(v[i]);
- a.push_back(res);
- }
- catch (invalid_argument e) {
- cout << "Caught invalid argument exception\n";
- cout << i;
- }
- }
- sort(a.begin(), a.end());
- int i = 0;
- for (i = a.size() - 1; i >= a.size() - k; i--) {
- sum_k += a[i] * 0.2;
- }
- for (i; i >= a.size() - k - m; i--) {
- sum_m += a[i] * 0.1;
- }
- cout << sum_k + sum_m << " " << a[i - 1];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement