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 med, count = 0;
- long long sum = 0;
- double half;
- vector <int> a;
- vector <string> v;
- string path = "nice.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 (std::invalid_argument e) {
- cout << "caught invalid argument exception\n";
- cout << i;
- }
- }
- for (int i = 0; i < (int)a.size(); i++) {
- sum += a[i];
- }
- sort(a.begin(), a.end());
- med = a[a.size() / 2];
- half = (double)sum / (double)a.size();
- cout << half << " " << med << endl;
- for (int i = 0; i < (int)a.size(); i++) {
- if (a[i] >= half && a[i] <= med)
- count++;
- }
- cout << count;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement