Advertisement
Rapptz

problem22

Dec 31st, 2012
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <utility>
  5. #include <algorithm>
  6. #include <sstream>
  7. #include <vector>
  8.  
  9. std::vector<std::string>& split(const std::string& str, char delimeter, std::vector<std::string>& vect) {
  10.     std::stringstream ss(str);
  11.     std::string item;
  12.     while (std::getline(ss, item, delimeter)) {
  13.         vect.push_back(item);
  14.     }
  15.     return vect;
  16. }
  17. int main() {
  18.     std::ifstream in("plane22.txt");
  19.     std::string str;
  20.     std::vector<std::string> holder;
  21.     std::vector<double> averages;
  22.     double total = 0;
  23.     while(std::getline(in,str)) {
  24.         std::replace_if(str.begin(),str.end(),[](char c) {return (c == '|' || c == ',');},' ');
  25.         split(str, ' ', holder);
  26.     }
  27.     for(size_t i = 1; i < holder.size()-2; i+=4) {
  28.         double y1 = std::stod(holder[i]);
  29.         double y2 = std::stod(holder[i+2]);
  30.         averages.push_back((y1+y2)/2);
  31.     }
  32.     for(auto& i : averages)
  33.         total += i;
  34.     std::cout << total;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement