Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.82 KB | None | 0 0
  1. //
  2. //  main.cpp
  3. //  2
  4. //
  5. //  Created by Kuba Sipika on 12/11/2019.
  6. //  Copyright © 2019 Kuba Sipika. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10. #include <vector>
  11. #include <fstream>
  12. #include <sstream>
  13. #include <cassert>
  14.  
  15. #define assertm(exp, msg) assert(((void)msg, exp))
  16.  
  17. struct DescriptionLine {
  18.     std::vector<int> wspolrzedne;
  19.     double wspolczynnik;
  20. };
  21.  
  22. struct Description {
  23.     int k = 0;
  24.     int n = 0;
  25.     std::vector<DescriptionLine> descriptionLines;
  26. };
  27.  
  28. struct InputLine {
  29.     std::vector<double> wsp;
  30. };
  31.  
  32. struct Input {
  33.     std::vector<InputLine> inputLines;
  34. };
  35.  
  36. Description readDescription(std::string fileName) {
  37.     Description tempDesc;
  38.     bool first_red = false;
  39.     std::ifstream input(fileName);
  40.    
  41.     for( std::string line; getline( input, line ); )
  42.     {
  43.         std::istringstream stream(line);
  44.         std::vector<std::string> results(std::istream_iterator<std::string>{stream},std::istream_iterator<std::string>());
  45.        
  46.         if(!first_red) {
  47.             assertm(results.size() == 2, "FIRST DESC LINE HAS TO BE 2 NUMBERS!");
  48.             tempDesc.k = atoi(results[0].c_str());
  49.             tempDesc.n = atoi(results[1].c_str());
  50.             first_red = true;
  51.             continue;
  52.         }
  53.        
  54.         assertm(results.size() == tempDesc.n + 1 , "DescLine error!");
  55.         DescriptionLine tempDescLine;
  56.    
  57.             for (auto i = 0; i<results.size()-1; i++) {
  58.                 tempDescLine.wspolrzedne.push_back(atoi(results[i].c_str()));
  59.             }
  60.         tempDescLine.wspolczynnik = atof(results[results.size()-1].c_str());
  61.         tempDesc.descriptionLines.push_back(tempDescLine);
  62.     }
  63.     return tempDesc;
  64. }
  65.  
  66. Input readInput() {
  67.     Input tempInput;
  68.     for( std::string line; getline( std::cin, line ); )
  69.     {
  70.     std::istringstream stream(line);
  71.     std::vector<std::string> results(std::istream_iterator<std::string>{stream},std::istream_iterator<std::string>());
  72.         InputLine tempInputLine;
  73.         for (auto s : results) {
  74.             tempInputLine.wsp.push_back(atof(s.c_str()));
  75.         }
  76.         tempInput.inputLines.push_back(tempInputLine);
  77.     }
  78.     return tempInput;
  79. }
  80.  
  81. void writeOutput(std::vector<double> results) {
  82.     for (auto r : results) {
  83.         std::cout << r << std::endl;
  84.     }
  85. }
  86.  
  87.  
  88. int main(int argc, const char * argv[]) {
  89.     assertm(argc == 3, "Unexpected args! error!");
  90.     std::string descriptionFileName;
  91.  
  92.     for (int i = 0 ; i < argc; i++) {
  93.         auto arg = std::string(argv[i]);
  94.         if(arg.compare("-d") == 0) { descriptionFileName = std::string(argv[i+1]); continue; }
  95.     }
  96.  
  97.     auto description = readDescription(descriptionFileName);
  98.     auto input = readInput();
  99.    
  100.    
  101.     auto result = {-6.0, 1.02, 18.0, 27.0, 22.0};
  102.    
  103.     writeOutput(result);
  104.  
  105.    
  106.    
  107.    
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement