Advertisement
Creadth

Untitled

Sep 25th, 2018
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. // ConsoleApplication1.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <fstream>
  6. #include <iostream>
  7. #include <vector>
  8. using namespace std;
  9.  
  10. std::vector<std::string> split(const std::string& s, char seperator)
  11. {
  12.     vector<std::string> output;
  13.  
  14.     std::string::size_type prev_pos = 0, pos = 0;
  15.  
  16.     while ((pos = s.find(seperator, pos)) != std::string::npos)
  17.     {
  18.         std::string substring(s.substr(prev_pos, pos - prev_pos));
  19.         if (substring != "")
  20.         {
  21.             output.push_back(substring);
  22.         }
  23.  
  24.         prev_pos = ++pos;
  25.     }
  26.  
  27.     output.push_back(s.substr(prev_pos, pos - prev_pos)); // Last word
  28.  
  29.     return output;
  30. }
  31.  
  32. int main()
  33. {
  34.     ifstream in;
  35.     ofstream out;
  36.     in.open("E:/out");
  37.     out.open("E:/in");
  38.     auto molId = 0;
  39.     while (!in.eof())
  40.     {
  41.         int cnt;
  42.         string comment;
  43.         in >> cnt;
  44.         getline(in, comment);
  45.         getline(in, comment);
  46.         auto isp = split(comment, ',');
  47.         auto fst = split(isp[0], '-');
  48.         auto l = std::to_string(molId) + ";" + fst[0] + ";" + fst[1] + ";" + fst[4] + ";" + fst[6] + ";" + isp[1] + ";" + isp[2] + ";" + isp[3];
  49.         for (auto i = 0; i < cnt; i++)
  50.         {
  51.             string line;
  52.             string clean;
  53.             getline(in, line);
  54.             clean = "";
  55.             auto fmt = split(line, ' ');
  56.             for (auto it = fmt.begin(); it != fmt.end(); it++)
  57.             {
  58.                 clean += *it + ";";
  59.             }
  60.             out << l << clean;
  61.         }
  62.         molId++;
  63.     }
  64.     in.close();
  65.     out.close();
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement