Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 21.69 KB | None | 0 0
  1. #include <iostream>  /* console "reading" */
  2. #include <fstream>   /* file reading */
  3. #include <cstring>   /* strncmp() */
  4. #include <sstream>   /* parse string of integers */
  5. #include <stdlib.h>  /* atoi */
  6. #include <chrono>    /* test proccess time elapsed */
  7. #include <algorithm>
  8. #include <vector>
  9. #include <string>
  10. #include <random>
  11.  
  12. /*
  13. * Run test or IO stream by default.
  14. * Make this variable 'false' to run tests.
  15. * */
  16. const bool kUseIoByDefault = true;
  17. /*
  18. * Stopes executing of the program in the end.
  19. * Make 'true' to see test results.
  20. * */
  21. const bool kStopConsoleProgramBeforeExit = false;
  22.  
  23. const std::string kTestFileA = "../resource/test-1.txt";
  24. const std::string kTestFileB = "../resource/test-2.txt";
  25. const std::string kTestFileC = "../resource/test-3.txt";
  26. const std::string kTestFileD = "../resource/test-4.txt";
  27. const std::string kTestFileE = "../resource/test-5.txt";
  28.  
  29. #ifndef READER_IO_H
  30. #define READER_IO_H
  31.  
  32. class ReaderIo {
  33. public:
  34.     ReaderIo();
  35.  
  36.     ~ReaderIo();
  37.  
  38.     unsigned int ReadNumber();
  39.  
  40.     std::vector<unsigned int> ReadNumbers(const unsigned int amount);
  41.  
  42.     std::vector<bool> ReadBools(const unsigned int amount);
  43. };
  44.  
  45. #endif // READER_IO_H
  46.  
  47. #ifndef RFILER_H
  48. #define RFILER_H
  49.  
  50. const char kDelimeter = ' ';
  51.  
  52. class RFiler {
  53. public:
  54.     RFiler();
  55.  
  56.     explicit RFiler(const std::string file_name);
  57.  
  58.     ~RFiler();
  59.  
  60.     bool Open(const std::string file_name = "");
  61.  
  62.     void Close();
  63.  
  64.     void Read();
  65.  
  66.     void PrintLastString();
  67.  
  68.     bool IsFileOpened();
  69.  
  70.     unsigned int ReadNumber();
  71.  
  72.     std::vector<unsigned int> ReadNumbers(const unsigned int amount);
  73.  
  74.     std::vector<bool> ReadBools(const unsigned int amount);
  75.  
  76.     bool SetLineNumber(const unsigned int new_line_number);
  77.  
  78.     bool IncreaseLineNumber(const unsigned int number_for = 1);
  79.  
  80.     bool DecreaseLineNumber(const unsigned int number_for = 1);
  81.  
  82. private:
  83.     std::ifstream current_file_stream_;
  84.     std::string current_file_name_;
  85.     unsigned int current_line_number_;
  86. };
  87.  
  88. #endif // RFILER_H
  89.  
  90. RFiler::RFiler() {}
  91.  
  92. RFiler::RFiler(const std::string file_name) {
  93.     this->current_file_name_ = file_name;
  94.     this->current_file_stream_.open(file_name.c_str());
  95. }
  96.  
  97. bool RFiler::Open(const std::string file_name) {
  98.     this->current_file_name_ = file_name;
  99.     this->current_file_stream_.open(file_name.c_str());
  100.     return this->IsFileOpened();
  101. }
  102.  
  103. void RFiler::Close() {
  104.     if (this->IsFileOpened()) {
  105.         this->current_file_stream_.close();
  106.     }
  107. }
  108.  
  109. void RFiler::Read() {
  110.     std::string line;
  111.  
  112.     if (this->current_file_stream_.is_open()) {
  113.         while (getline(this->current_file_stream_, line)) {
  114.             std::cout << line << '\n';
  115.         }
  116.         this->current_file_stream_.close();
  117.     } else {
  118.         std::cout << "File for reading \""
  119.                   << this->current_file_name_ << "\" is closed!\n";
  120.     }
  121. }
  122.  
  123. void RFiler::PrintLastString() {
  124.     std::string line;
  125.  
  126.     if (this->current_file_stream_.is_open()) {
  127.         while (getline(this->current_file_stream_, line)) {
  128.             // do nothing, just getting last string
  129.         }
  130.         std::cout << line << '\n';
  131.         this->current_file_stream_.close();
  132.     } else {
  133.         std::cout << "File for reading \""
  134.                   << this->current_file_name_ << "\" is closed!\n";
  135.     }
  136. }
  137.  
  138. bool RFiler::IsFileOpened() {
  139.     return this->current_file_stream_.is_open();
  140. }
  141.  
  142. unsigned int RFiler::ReadNumber() {
  143.     std::string line;
  144.     unsigned int result = 0;
  145.  
  146.     if (this->current_file_stream_.is_open()) {
  147.         if (getline(this->current_file_stream_, line)) {
  148.             result = atoi(line.c_str());
  149.         } else {
  150.             std::cout << "Error occurred while file \""
  151.                       << this->current_file_name_ << "\" reading - no lines!\n";
  152.         }
  153.         ++this->current_line_number_;
  154.     } else {
  155.         std::cout << "File for reading \""
  156.                   << this->current_file_name_ << "\" is closed!\n";
  157.     }
  158.  
  159.     return result;
  160. }
  161.  
  162. std::vector<unsigned int> RFiler::ReadNumbers(const unsigned int amount) {
  163.     std::string line, token;
  164.     std::stringstream string_stream;
  165.     std::vector<unsigned int> result(amount);
  166.  
  167.     if (this->current_file_stream_.is_open()) {
  168.         if (getline(this->current_file_stream_, line)) {
  169.             string_stream.str(line);
  170.             for (unsigned int iter = 0; iter < amount; ++iter) {
  171.                 std::getline(string_stream, token, kDelimeter);
  172.                 result[iter] = atoi(token.c_str());
  173.             }
  174.         } else {
  175.             std::cout << "Error occurred while file \""
  176.                       << this->current_file_name_ << "\" reading - no lines!\n";
  177.         }
  178.         ++this->current_line_number_;
  179.     } else {
  180.         std::cout << "File for reading \""
  181.                   << this->current_file_name_ << "\" is closed!\n";
  182.     }
  183.  
  184.     return result;
  185. }
  186.  
  187. std::vector<bool> RFiler::ReadBools(const unsigned int amount) {
  188.     std::string line;
  189.     std::vector<bool> result(amount);
  190.  
  191.     if (this->current_file_stream_.is_open()) {
  192.         if (getline(this->current_file_stream_, line)) {
  193.             for (unsigned int iter = 0; iter < amount; ++iter) {
  194.                 result[iter] = line[iter] == 'R';
  195.             }
  196.         } else {
  197.             std::cout << "Error occurred while file \""
  198.                       << this->current_file_name_ << "\" reading - no lines!\n";
  199.         }
  200.         ++this->current_line_number_;
  201.     } else {
  202.         std::cout << "File for reading \""
  203.                   << this->current_file_name_ << "\" is closed!\n";
  204.     }
  205.  
  206.     return result;
  207. }
  208.  
  209. bool RFiler::SetLineNumber(const unsigned int new_line_number) {
  210.     if (new_line_number > this->current_line_number_) {
  211.         return this->IncreaseLineNumber(new_line_number -
  212.                                         this->current_line_number_);
  213.     } else if (new_line_number < this->current_line_number_) {
  214.         return this->IncreaseLineNumber(this->current_line_number_ -
  215.                                         new_line_number);
  216.     }
  217.     return true;
  218. }
  219.  
  220. bool RFiler::IncreaseLineNumber(const unsigned int number_for) {
  221.     std::string line;
  222.     for (unsigned int iter = 0; iter < number_for; ++iter) {
  223.         if (!getline(this->current_file_stream_, line)) {
  224.             return false;
  225.         }
  226.         ++this->current_line_number_;
  227.     }
  228.     return true;
  229. }
  230.  
  231. bool RFiler::DecreaseLineNumber(const unsigned int number_for) {
  232.     std::string line;
  233.     unsigned int new_position = current_line_number_ - number_for;
  234.  
  235.     if (new_position < 0) {
  236.         return false;
  237.     }
  238.     this->current_file_stream_.seekg(0, this->current_file_stream_.beg);
  239.  
  240.     for (unsigned int iter = 0; iter < new_position; ++iter) {
  241.         if (!getline(this->current_file_stream_, line)) {
  242.             return false;
  243.         }
  244.         ++this->current_line_number_;
  245.     }
  246.     return true;
  247. }
  248.  
  249. RFiler::~RFiler() {
  250.     if (this->IsFileOpened()) {
  251.         this->current_file_stream_.close();
  252.     }
  253. }
  254.  
  255. ReaderIo::ReaderIo() {}
  256.  
  257. unsigned int ReaderIo::ReadNumber() {
  258.     unsigned int result = 0;
  259.     std::cin >> result;
  260.     return result;
  261. }
  262.  
  263. std::vector<unsigned int> ReaderIo::ReadNumbers(const unsigned int amount) {
  264.     std::vector<unsigned int> result(amount);
  265.  
  266.     for (unsigned int iter = 0; iter < amount; ++iter) {
  267.         std::cin >> result[iter];
  268.     }
  269.     return result;
  270. }
  271.  
  272. std::vector<bool> ReaderIo::ReadBools(const unsigned int amount) {
  273.     std::vector<bool> result(amount);
  274.     char tmpp;
  275.  
  276.     for (unsigned int iter = 0; iter < amount; ++iter) {
  277.         std::cin >> tmpp;
  278.         result[iter] = tmpp == 'R';
  279.     }
  280.     return result;
  281. }
  282.  
  283. ReaderIo::~ReaderIo() {}
  284.  
  285. #ifndef HEAP_H
  286. #define HEAP_H
  287.  
  288. typedef enum {
  289.     none, smallest_numbers, non_allocated_numbers
  290. } placement;
  291.  
  292. struct HeapElement {
  293. public:
  294.     unsigned int value;
  295.     unsigned int heap_position;
  296.     unsigned int array_position;
  297.     placement which_heap_in;
  298.  
  299.     HeapElement();
  300.  
  301.     HeapElement(unsigned int value, unsigned int heap_position = 0,
  302.                 placement which_heap_in = placement::none);
  303. };
  304.  
  305. class Heap {
  306. public:
  307.     Heap();
  308.  
  309.     void Insert(HeapElement *element);
  310.  
  311.     void Remove(HeapElement *element);
  312.  
  313.     void Remove(unsigned int index);
  314.  
  315.     HeapElement *GetTopValue();
  316.  
  317.     unsigned int GetSize();
  318.  
  319.     void Clear();
  320.  
  321. private:
  322.     std::vector<HeapElement *> queue_;
  323.     unsigned int size_;
  324.  
  325.     virtual bool Comparator(unsigned int value_a, unsigned int value_b) = 0;
  326.  
  327.     int GetParent(unsigned int index) const;
  328.  
  329.     int GetChild(unsigned int index) const;
  330.  
  331.     int Find(unsigned int index, HeapElement *element) const;
  332.  
  333.     unsigned int GetMinimumIndex(unsigned int index_a,
  334.                                  unsigned int index_b, unsigned int index_c);
  335.  
  336.     void BubbleUp(int index);
  337.  
  338.     void BubbleDown(unsigned int index);
  339. };
  340.  
  341. class HeapDesc : public Heap {
  342. private:
  343.     bool Comparator(unsigned int value_a, unsigned int value_b);
  344. };
  345.  
  346. class HeapAsc : public Heap {
  347. private:
  348.     bool Comparator(unsigned int value_a, unsigned int value_b);
  349. };
  350.  
  351. #endif // HEAP_H
  352.  
  353. #ifndef SLIDINGSTATISTICS_H
  354. #define SLIDINGSTATISTICS_H
  355.  
  356. class SlidingStatistics {
  357. public:
  358.     SlidingStatistics();
  359.  
  360.     ~SlidingStatistics();
  361.  
  362.     void ReadNumbers(const std::vector<unsigned int> numbers);
  363.  
  364.     void SetOffset(const unsigned int offset);
  365.  
  366.     std::vector<int> MoveSlides(const std::vector<bool> slide_right_point_array);
  367.  
  368. private:
  369.     unsigned int iterator_right_;
  370.     unsigned int iterator_left_;
  371.     unsigned int offset_;
  372.     HeapDesc smallest_numbers_;
  373.     HeapAsc non_allocated_numbers_;
  374.     std::vector<HeapElement *> all_numbers_;
  375. };
  376.  
  377. #endif // SLIDINGSTATISTICS_H
  378.  
  379. HeapElement::HeapElement(unsigned int value,
  380.                          unsigned int heap_position, placement which_heap_in) {
  381.     this->value = value;
  382.     this->array_position = 0;
  383.     this->heap_position = heap_position;
  384.     this->which_heap_in = which_heap_in;
  385. }
  386.  
  387. HeapElement::HeapElement() {
  388.     this->value = 0;
  389.     this->heap_position = 0;
  390.     this->array_position = 0;
  391.     this->which_heap_in = placement::none;
  392. }
  393.  
  394. Heap::Heap() {
  395.     this->Clear();
  396. }
  397.  
  398. unsigned int Heap::GetSize() {
  399.     return this->size_;
  400. }
  401.  
  402. void Heap::Clear() {
  403.     this->queue_.clear();
  404.     this->size_ = 0;
  405. }
  406.  
  407. int Heap::GetParent(unsigned int index) const {
  408.     if (this->size_ < 1) {
  409.         return -1; // empty or root has no parent
  410.     }
  411.     return (static_cast<int> (index - 1) / 2);
  412. }
  413.  
  414. int Heap::GetChild(unsigned int index) const {
  415.     if (this->size_ <= 1 || 2 * (index + 1) > this->size_) {
  416.         return -1; // empty or root has no child
  417.     }
  418.     return (2 * (index + 1));
  419. }
  420.  
  421. int Heap::Find(unsigned int index, HeapElement *element) const {
  422.     if (index + 1 > this->size_) {
  423.         return -1; // base case: index out of bounds
  424.     }
  425.     if (element->value < this->queue_[index]->value) {
  426.         return -1;   // base case: val not in min-heap
  427.     }
  428.     if (this->queue_[index]->value == element->value) {
  429.         return index; // Found the value, return its index
  430.     }
  431.  
  432.     int child_index = this->GetChild(index);
  433.     int max_from_children = -1;
  434.  
  435.     if (child_index != -1) {
  436.         max_from_children = std::max(this->Find(child_index, element),
  437.                                      this->Find(child_index - 1, element));
  438.     }
  439.  
  440.     return max_from_children;
  441. }
  442.  
  443. void Heap::BubbleUp(int index) {
  444.     int parent_index = this->GetParent(index);
  445.  
  446.     if (parent_index == -1 || parent_index == index) {
  447.         return; // base case: root of heap
  448.     }
  449.  
  450.     if (!this->Comparator(this->queue_[parent_index]->value,
  451.                           this->queue_[index]->value)) {
  452.         this->queue_[parent_index]->heap_position = index;
  453.         this->queue_[index]->heap_position = parent_index;
  454.         std::swap(this->queue_[parent_index], this->queue_[index]);
  455.         this->BubbleUp(parent_index);
  456.     }
  457. }
  458.  
  459. void Heap::Insert(HeapElement *element) {
  460.     element->heap_position = this->size_;
  461.     this->queue_.push_back(element);
  462.     this->BubbleUp(size_);
  463.     this->size_++;
  464. }
  465.  
  466. unsigned int Heap::GetMinimumIndex(unsigned int index_a,
  467.                                    unsigned int index_b, unsigned int index_c) {
  468.     bool left_smaller = this->Comparator
  469.             (this->queue_[index_a]->value, this->queue_[index_b]->value);
  470.  
  471.     if (index_c >= (unsigned int) this->size_) {
  472.         return left_smaller ? index_a : index_b;
  473.     } else if (left_smaller) {
  474.         return this->Comparator
  475.                 (this->queue_[index_a]->value, this->queue_[index_c]->value) ?
  476.                index_a : index_c;
  477.     } else {
  478.         return this->Comparator
  479.                 (this->queue_[index_b]->value, this->queue_[index_c]->value) ?
  480.                index_b : index_c;
  481.     }
  482. }
  483.  
  484. void Heap::BubbleDown(unsigned int index) {
  485.     int child_index = this->GetChild(index);
  486.  
  487.     if (child_index == -1) {
  488.         return; // base case: no children left
  489.     }
  490.     unsigned int minimum_index = this->GetMinimumIndex
  491.             (index, child_index - 1, child_index);
  492.  
  493.     if (minimum_index != index) {
  494.         this->queue_[minimum_index]->heap_position = index;
  495.         this->queue_[index]->heap_position = minimum_index;
  496.         std::swap(this->queue_[minimum_index], this->queue_[index]);
  497.         this->BubbleDown(minimum_index);
  498.     }
  499. }
  500.  
  501. void Heap::Remove(HeapElement *element) {
  502.     this->Remove(element->heap_position);
  503.     element->which_heap_in = placement::none;
  504.     element->heap_position = 0;
  505. }
  506.  
  507. void Heap::Remove(unsigned int index) {
  508.     --this->size_;
  509.     this->queue_[index] = this->queue_[this->size_];
  510.     this->queue_[index]->heap_position = index;
  511.     this->queue_.resize(this->size_);
  512.     this->BubbleDown(index);
  513.     this->BubbleUp(index);
  514. }
  515.  
  516. HeapElement *Heap::GetTopValue() {
  517.     if (this->size_ == 0) {
  518.         return nullptr;
  519.     }
  520.     return this->queue_[0];
  521. }
  522.  
  523. bool HeapDesc::Comparator(unsigned int value_a, unsigned int value_b) {
  524.     return value_a > value_b;
  525. }
  526.  
  527. bool HeapAsc::Comparator(unsigned int value_a, unsigned int value_b) {
  528.     return value_a < value_b;
  529. }
  530.  
  531. SlidingStatistics::SlidingStatistics() {}
  532.  
  533. SlidingStatistics::~SlidingStatistics() {
  534.     for (unsigned int iter = 0; iter < this->all_numbers_.size(); ++iter) {
  535.         delete this->all_numbers_[iter];
  536.     }
  537. }
  538.  
  539. void SlidingStatistics::ReadNumbers(std::vector<unsigned int> numbers) {
  540.     // pushing first number to Heap & adding other to array
  541.     unsigned int iter, numbers_amount = numbers.size();
  542.     this->all_numbers_.resize(numbers_amount);
  543.  
  544.     HeapElement *first_element = new HeapElement();
  545.     first_element->value = numbers[0];
  546.     first_element->array_position = 0;
  547.     first_element->which_heap_in = placement::smallest_numbers;
  548.     this->smallest_numbers_.Insert(first_element);
  549.     this->all_numbers_[0] = first_element;
  550.  
  551.     this->iterator_right_ = 1;
  552.     this->iterator_left_ = 0;
  553.  
  554.     for (iter = 1; iter < numbers_amount; ++iter) {
  555.         this->all_numbers_[iter] = new HeapElement(numbers[iter]);
  556.         this->all_numbers_[iter]->array_position = iter;
  557.     }
  558. }
  559.  
  560. void SlidingStatistics::SetOffset(unsigned int offset) {
  561.     this->offset_ = offset;
  562. }
  563.  
  564. std::vector<int> SlidingStatistics::MoveSlides(std::vector<bool> slide_right_point_array) {
  565.     unsigned int slides_amount = slide_right_point_array.size();
  566.     std::vector<int> result;
  567.     HeapElement *tmp_value;
  568.  
  569.     for (unsigned int iter = 0; iter < slides_amount; ++iter) {
  570.         // moving slide
  571.         if (slide_right_point_array[iter]) {
  572.             tmp_value = this->all_numbers_[this->iterator_right_];
  573.  
  574.             tmp_value->which_heap_in = placement::smallest_numbers;
  575.             this->smallest_numbers_.Insert(tmp_value);
  576.  
  577.             while (this->smallest_numbers_.GetSize() >= this->offset_) {
  578.                 tmp_value = this->smallest_numbers_.GetTopValue();
  579.                 this->smallest_numbers_.Remove(tmp_value);
  580.  
  581.                 tmp_value->which_heap_in = placement::non_allocated_numbers;
  582.                 this->non_allocated_numbers_.Insert(tmp_value);
  583.             }
  584.             ++this->iterator_right_;
  585.         } else {
  586.             tmp_value = this->all_numbers_[this->iterator_left_];
  587.  
  588.             if (tmp_value->which_heap_in == placement::non_allocated_numbers) {
  589.                 this->non_allocated_numbers_.Remove(tmp_value);
  590.             } else if (tmp_value->which_heap_in == placement::smallest_numbers) {
  591.                 this->smallest_numbers_.Remove(tmp_value);
  592.  
  593.                 if (this->non_allocated_numbers_.GetSize() > 0) {
  594.                     tmp_value = this->non_allocated_numbers_.GetTopValue();
  595.                     this->non_allocated_numbers_.Remove(tmp_value);
  596.  
  597.                     tmp_value->which_heap_in = placement::smallest_numbers;
  598.                     this->smallest_numbers_.Insert(tmp_value);
  599.                 }
  600.             } else {
  601.                 std::cout << "Error! Can't remove item " << tmp_value->value
  602.                           << " - it's not locatted in any heap." << std::endl;
  603.             }
  604.  
  605.             ++this->iterator_left_;
  606.         }
  607.  
  608.         // getting the smallest number
  609.         tmp_value = this->non_allocated_numbers_.GetTopValue();
  610.         if (tmp_value && tmp_value->value) {
  611.             result.push_back(tmp_value->value);
  612.         } else {
  613.             result.push_back(-1);
  614.         }
  615.     }
  616.  
  617.     return result;
  618. }
  619.  
  620.  
  621. inline void TestFile(std::string file_to_run = kTestFileA) {
  622.     double elapsed;
  623.     std::vector<int> result;
  624.     std::vector<unsigned int> tmp_integers;
  625.     std::vector<bool> tmp_bools;
  626.     unsigned int numbers_amount, slides_amount;
  627.     SlidingStatistics sliding_statistics;
  628.     RFiler filer(file_to_run);
  629.  
  630.     tmp_integers = filer.ReadNumbers(3);
  631.     numbers_amount = tmp_integers[0];
  632.     slides_amount = tmp_integers[1];
  633.     sliding_statistics.SetOffset(tmp_integers[2]);
  634.  
  635.     tmp_integers = filer.ReadNumbers(numbers_amount);
  636.     tmp_bools = filer.ReadBools(slides_amount);
  637.  
  638.     std::cout << "Testing file '" << file_to_run << "'" << std::endl;
  639.     auto begin = std::chrono::steady_clock::now();
  640.  
  641.     sliding_statistics.ReadNumbers(tmp_integers);
  642.     result = sliding_statistics.MoveSlides(tmp_bools);
  643.  
  644.     std::cout << "Result:   " << std::endl;
  645.     for (auto element : result) {
  646.         std::cout << element << std::endl;
  647.     }
  648.     result.clear();
  649.  
  650.     elapsed = std::chrono::duration_cast<std::chrono::microseconds>
  651.                       (std::chrono::steady_clock::now() - begin).count() * 0.000001;
  652.  
  653.     std::cout << "Expected: " << std::endl;
  654.     filer.Read();
  655.     filer.Close();
  656.  
  657.     std::cout << "Proccess finished in " << elapsed << " seconds." << std::endl;
  658. }
  659.  
  660. inline void RunTest() {
  661.     TestFile(kTestFileA);
  662.     TestFile(kTestFileB);
  663.     TestFile(kTestFileC);
  664.     TestFile(kTestFileD);
  665.     TestFile(kTestFileE);
  666. }
  667.  
  668. int main(int argc, char *argv[]) {
  669.     ReaderIo reader_io;
  670.     RFiler filer;
  671.     std::string file_name;
  672.     std::vector<int> result;
  673.     std::vector<unsigned int> tmp_integers;
  674.     std::vector<bool> tmp_bools;
  675.     unsigned int numbers_amount, slides_amount;
  676.     SlidingStatistics sliding_statistics;
  677.  
  678.     std::ios_base::sync_with_stdio(false);
  679.  
  680.     if (argc == 1) {
  681.         if (kUseIoByDefault) {
  682.             tmp_integers = reader_io.ReadNumbers(3);
  683.             numbers_amount = tmp_integers[0];
  684.             slides_amount = tmp_integers[1];
  685.             sliding_statistics.SetOffset(tmp_integers[2]);
  686.  
  687.             tmp_integers = reader_io.ReadNumbers(numbers_amount);
  688.             tmp_bools = reader_io.ReadBools(slides_amount);
  689.             sliding_statistics.ReadNumbers(tmp_integers);
  690.  
  691.             result = sliding_statistics.MoveSlides(tmp_bools);
  692.             for (auto element : result) {
  693.                 std::cout << element << std::endl;
  694.             }
  695.         } else {
  696.             RunTest();
  697.         }
  698.     } else {
  699.         if (strcmp(argv[1], "--test") == 0) {
  700.             RunTest();
  701.         } else {
  702.             if (strcmp(argv[1], "--file") == 0) {
  703.                 if (argc == 3) {
  704.                     file_name = argv[2];
  705.                 } else {
  706.                     file_name = kTestFileA;
  707.                 }
  708.                 filer.Open(file_name);
  709.                 tmp_integers = filer.ReadNumbers(3);
  710.                 numbers_amount = tmp_integers[0];
  711.                 slides_amount = tmp_integers[1];
  712.                 sliding_statistics.SetOffset(tmp_integers[2]);
  713.  
  714.                 tmp_integers = filer.ReadNumbers(numbers_amount);
  715.                 tmp_bools = filer.ReadBools(slides_amount);
  716.                 filer.Close();
  717.             } else if (strcmp(argv[1], "--io") == 0) {
  718.                 tmp_integers = reader_io.ReadNumbers(3);
  719.                 numbers_amount = tmp_integers[0];
  720.                 slides_amount = tmp_integers[1];
  721.                 sliding_statistics.SetOffset(tmp_integers[2]);
  722.  
  723.                 tmp_integers = reader_io.ReadNumbers(numbers_amount);
  724.                 tmp_bools = reader_io.ReadBools(slides_amount);
  725.             } else {
  726.                 std::cout << "No programm input specified." << std::endl;
  727.                 if (kStopConsoleProgramBeforeExit) {
  728.                     std::cout << "Press enter to exit program.";
  729.                     std::cin.get();
  730.                 }
  731.                 return 0;
  732.             }
  733.  
  734.             sliding_statistics.ReadNumbers(tmp_integers);
  735.             result = sliding_statistics.MoveSlides(tmp_bools);
  736.             for (auto element : result) {
  737.                 std::cout << element << std::endl;
  738.             }
  739.         }
  740.     }
  741.     if (kStopConsoleProgramBeforeExit) {
  742.         std::cout << "Press enter to exit program.";
  743.         std::cin.get();
  744.     }
  745.     return 0;
  746. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement