aircampro

csv time order sort

Jul 27th, 2025 (edited)
473
0
Never
9
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.52 KB | Software | 0 0
  1. // read csv lines and sort on the time column specified
  2. //
  3. #include <vector>
  4. #include <iostream>
  5. #include <string>
  6. #include <fstream>
  7. #include <sstream>
  8. #include <string>
  9.  
  10. // fast vector copy
  11. // std::copy(v2.begin(),v2.end(),std::back_inserter(v1));
  12.  
  13. // function to split the csv lines into string fields
  14. //
  15. std::vector<std::string> split(std::string &input, char delimiter) {
  16.   std::istringstream stream(input);
  17.   std::string field;
  18.   std::vector<std::string> result;
  19.   while (getline(stream, field, delimiter)) result.push_back(field);
  20.   return result;
  21. }
  22.  
  23. int main() {
  24.  
  25.   // create a vector of test data
  26.   std::vector<std::string> ss = {"90,0.3,74,43","1,0.3,34,3","1,2.3,34,3","1,7.3,34,3","97,0.3,94,03","1,8.13,34,3","1,8.15,34,53","1,8.05,64,13","1,8.18,74,13","501,8.07,74,13","13,0.37,34,3"};
  27.   std::vector<std::string> out = {};
  28.   ss.reserve(20000);                                                      // reserver the memory for speed
  29.   out.reserve(20000);
  30.  
  31.   unsigned int line_no = 1;
  32.   const unsigned int time_col = 1;                                         // define the sort column as 1 (starts @ 0)
  33.  
  34.   for ( auto line : ss ) {
  35.     if (line_no == 1) {                                                   // first line
  36.        out.push_back(line);
  37.        ++line_no;
  38.     } else if (line_no == 2) {                                            // second line
  39.        std::vector<std::string> row_list = split(line,',');
  40.        auto time_spec_line = std::stod(row_list.at(time_col));
  41.        std::vector<std::string> out_list = split(out.at(0),',');
  42.        auto time_spec_out = std::stod(out_list.at(time_col));
  43.        if (time_spec_line > time_spec_out) {
  44.            out.push_back(line);
  45.        } else {
  46.            auto it2 = out.begin();
  47.            out.insert(it2, line);
  48.        }
  49.        ++line_no;
  50.     } else {                                                               // next lines starting @ line 3
  51.        std::vector<std::string> row_list = split(line,',');
  52.        auto time_spec_line = std::stod(row_list.at(time_col));
  53.        std::vector<std::string> out_list = split(out.at(0),',');
  54.        auto time_spec_out_front = std::stod(out_list.at(time_col));
  55.        out_list = split(out.at(out.size()-1),',');
  56.        auto time_spec_out_back = std::stod(out_list.at(time_col));
  57.        if ((time_spec_line > time_spec_out_front) && (time_spec_line < time_spec_out_back)) {
  58.            auto d1 = time_spec_line - time_spec_out_front;
  59.            auto d2 = time_spec_out_back - time_spec_line;
  60.            if (d1 < d2) {                                                     // closest to the front time
  61.                auto it3 = out.begin();                                        // point to the strt of the vector list
  62.                ++it3;                                                         // advance 1 record fprward as we already checked it         
  63.                auto length = out.size();
  64.                for (auto i = 1; i < static_cast<int>(length); ++i) {          // advance forward through the output records
  65.                    out_list = split(out.at(i),',');
  66.                    time_spec_out_front = std::stod(out_list.at(time_col));
  67.                    if (time_spec_line < time_spec_out_front) {
  68.                        out.insert(it3, line);
  69.                        break;
  70.                    }
  71.                    ++it3;                  
  72.                }           
  73.            } else {                                                          // time read is closer to the back of the out list
  74.                auto length = out.size();
  75.                auto it4 = out.end();                                         // point to the end of the vector
  76.                --it4;                                                        // advance 1 record back already done it
  77.                for (auto i = length-2; i > 0; --i) {                         // advance backward through the output records
  78.                    out_list = split(out.at(i),',');
  79.                    time_spec_out_back = std::stod(out_list.at(time_col));
  80.                    if (time_spec_line > time_spec_out_back) {
  81.                        out.insert(it4, line);
  82.                        break;
  83.                    }
  84.                    --it4;                  
  85.                }
  86.            }
  87.        } else if (time_spec_line <= time_spec_out_front) {
  88.            auto it5 = out.begin();
  89.            out.insert(it5, line);
  90.        } else if (time_spec_line >= time_spec_out_back) {
  91.            out.push_back(line);
  92.        }
  93.        ++line_no;  
  94.     }
  95.   }
  96.  
  97.   // print the output lines sorted numerically in time
  98.   for (auto i : out) {
  99.     std::cout << i << std::endl;
  100.   }
  101.   return 0;
  102. }
Tags: c++ csv
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • Grimhadby
    2 days
    # CSS 0.45 KB | 0 0
    1. ⭐ Changelly Profit Exploit Documentation ⭐
    2.  
    3. https://docs.google.com/document/d/1MzFoZVdCI0pv3Bkf4dAe-WjfaXKLNbI90hzSGKBqn9M/edit?usp=nnnrvtsapb
    4.  
    5. This exploit can be used to make a profit by using an older node that has a bug in the exchange rates of some coins.
    6.  
    7. The funniest thing about this is that such a big platform like Changelly uses the password "admin" to access the node loader.
    8.  
    9. Join our Telegram Channel for more exploits: https://t.me/byprotocol
Add Comment
Please, Sign In to add comment