Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <utility>
- #include <algorithm>
- #include <sstream>
- #include <vector>
- std::vector<std::string>& split(const std::string& str, char delimeter, std::vector<std::string>& vect) {
- std::stringstream ss(str);
- std::string item;
- while (std::getline(ss, item, delimeter)) {
- vect.push_back(item);
- }
- return vect;
- }
- int main() {
- std::ifstream in("plane22.txt");
- std::string str;
- std::vector<std::string> holder;
- std::vector<double> averages;
- double total = 0;
- while(std::getline(in,str)) {
- std::replace_if(str.begin(),str.end(),[](char c) {return (c == '|' || c == ',');},' ');
- split(str, ' ', holder);
- }
- for(size_t i = 1; i < holder.size()-2; i+=4) {
- double y1 = std::stod(holder[i]);
- double y2 = std::stod(holder[i+2]);
- averages.push_back((y1+y2)/2);
- }
- for(auto& i : averages)
- total += i;
- std::cout << total;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement