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 count = 0;
- int k = 0, f = 0, max = 0;
- vector <int> a;
- vector <int> even;
- vector <int> uneven;
- vector <string> v;
- string path = "stat.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());
- for (int i = 0; i < (int)a.size(); i++) {
- if (a[i] % 2 == 0)
- even.push_back(a[i]);
- else if (a[i] % 2 == 1)
- uneven.push_back(a[i]);
- }
- for (int i = 0; i < even.size(); i++) {
- for (int j = 0; j < uneven.size(); j++) {
- k = even[i] + uneven[j];
- vector<int>::iterator it = find(uneven.begin(), uneven.end(), k);
- if (it != uneven.end()) {
- count++;
- if (max < *it)
- max = *it;
- }
- }
- }
- cout << count << " " << max;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement