Advertisement
Guest User

oppa

a guest
Jun 6th, 2021
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int pow(int step) {
  6.     if (step < 0) return -666;
  7.     if (step == 0) return 1;
  8.     if (step == 1) return 10;
  9.     return 10 * pow(--step);
  10. }
  11.  
  12. struct razvilka {
  13.     int _A;
  14.     int _B;
  15.     int dlina;
  16.  
  17.     struct core {
  18.         string path;
  19.         int dlina_path;
  20.         core() {
  21.             dlina_path = 0;
  22.         }
  23.         core(string path, int dlina_path) {
  24.             this->path = path;
  25.             this->dlina_path = dlina_path;
  26.         }
  27.     };
  28.  
  29.     struct head {
  30.         vector<core> historylal;
  31.         head() {
  32.            
  33.         }
  34.     };
  35.  
  36.     head left;
  37.     head right;
  38.  
  39.     core podbitb(const core& object, string histor, int dlin_histor) {
  40.         core objectmy = object;
  41.         objectmy.path += histor;
  42.         objectmy.dlina_path += dlin_histor;
  43.         return objectmy;
  44.     }
  45.  
  46.     void makehistorylal_forright(const razvilka& copirka, int mode) {
  47.         if (mode == 1) {
  48.             for (int i = 0; i < copirka.left.historylal.size(); i++) {
  49.                 string histor = { 'a','d' };
  50.                 this->right.historylal.push_back(core(podbitb(copirka.left.historylal[i] ,histor,this->_A + this->dlina )));
  51.             }
  52.             for (int i = 0; i < copirka.left.historylal.size(); i++) {
  53.                 string histor = { 'd', 'b' };
  54.                 this->right.historylal.push_back(core(podbitb(copirka.left.historylal[i], histor, this->_B + copirka.dlina)));
  55.             }
  56.         } else {
  57.             for (int i = 0; i < copirka.left.historylal.size(); i++) {
  58.                 string histor = { 'd' };
  59.                 this->right.historylal.push_back(core(podbitb(copirka.right.historylal[i], histor, this->_B)));
  60.             }
  61.             for (int i = 0; i < copirka.left.historylal.size(); i++) {
  62.                 string histor = { 'd', 'a', 'd' };
  63.                 this->right.historylal.push_back(core(podbitb(copirka.right.historylal[i], histor, copirka.dlina + this->_A + this->dlina)));
  64.             }
  65.         }
  66.     }
  67.  
  68.     void makehistorylal_forleft(const razvilka& copirka, int mode) {
  69.         if (mode == 1) {
  70.             for (int i = 0; i < copirka.left.historylal.size(); i++) {
  71.                 string histor = {'a'};
  72.                 this->left.historylal.push_back(core(podbitb(copirka.left.historylal[i], histor, this->_A)));
  73.             }
  74.             for (int i = 0; i < copirka.left.historylal.size(); i++) {
  75.                 string histor = { 'd', 'b', 'd' };
  76.                 this->left.historylal.push_back(core(podbitb(copirka.left.historylal[i], histor, copirka.dlina + this->_B + this->dlina)));
  77.             }
  78.         } else {
  79.             for (int i = 0; i < copirka.left.historylal.size(); i++) {
  80.                 string histor = { 'b', 'd' };
  81.                 this->left.historylal.push_back(core(podbitb(copirka.right.historylal[i], histor, this->_B + this->dlina)));
  82.             }
  83.             for (int i = 0; i < copirka.left.historylal.size(); i++) {
  84.                 string histor = { 'd', 'a' };
  85.                 this->left.historylal.push_back(core(podbitb(copirka.right.historylal[i], histor, copirka.dlina + this->_A)));
  86.             }
  87.         }
  88.     }
  89.  
  90.     razvilka() {
  91.         _A = 0;
  92.         _B = 0;
  93.         dlina = 0;
  94.     }
  95. };
  96.  
  97. int main() {
  98.     int N;
  99.     cout << "enter N: ";
  100.     cin >> N;
  101.     cout << endl;
  102.     //0000000000000//
  103.     vector<razvilka> allrazv;
  104.     for (int i = 0; i < N; i++) {
  105.         allrazv.push_back(razvilka());
  106.     }
  107.     //0000000000000//
  108.     int iteraq = -1;
  109.     cout << "enter proprities (x for accept): " << endl;
  110.     while (++iteraq != N) {
  111.         string inputdata;
  112.         char buffer = ' ';
  113.         while (buffer != 'x') {
  114.             inputdata.push_back(buffer);
  115.             buffer = cin.get();
  116.         }
  117.         //0000000000000000//
  118.         vector<int> number;
  119.         vector<int> number2;
  120.         vector<int> number3;
  121.         int flag = 0;
  122.         for (int i = 1; i < inputdata.size(); i++) {
  123.             if (inputdata[i] != ' ' && inputdata[i] != ',' && inputdata[i] != '\n') {
  124.                 switch (flag) {
  125.                 case 0:
  126.                     switch (inputdata[i]) {
  127.                     case '0':
  128.                         number.push_back(0);
  129.                         break;
  130.                     case '1':
  131.                         number.push_back(1);
  132.                         break;
  133.                     case '2':
  134.                         number.push_back(2);
  135.                         break;
  136.                     case '3':
  137.                         number.push_back(3);
  138.                         break;
  139.                     case '4':
  140.                         number.push_back(4);
  141.                         break;
  142.                     case '5':
  143.                         number.push_back(5);
  144.                         break;
  145.                     case '6':
  146.                         number.push_back(6);
  147.                         break;
  148.                     case '7':
  149.                         number.push_back(7);
  150.                         break;
  151.                     case '8':
  152.                         number.push_back(8);
  153.                         break;
  154.                     case '9':
  155.                         number.push_back(9);
  156.                         break;
  157.                     }
  158.                     break;
  159.                 case 1:
  160.                     switch (inputdata[i]) {
  161.                     case '0':
  162.                         number2.push_back(0);
  163.                         break;
  164.                     case '1':
  165.                         number2.push_back(1);
  166.                         break;
  167.                     case '2':
  168.                         number2.push_back(2);
  169.                         break;
  170.                     case '3':
  171.                         number2.push_back(3);
  172.                         break;
  173.                     case '4':
  174.                         number2.push_back(4);
  175.                         break;
  176.                     case '5':
  177.                         number2.push_back(5);
  178.                         break;
  179.                     case '6':
  180.                         number2.push_back(6);
  181.                         break;
  182.                     case '7':
  183.                         number2.push_back(7);
  184.                         break;
  185.                     case '8':
  186.                         number2.push_back(8);
  187.                         break;
  188.                     case '9':
  189.                         number2.push_back(9);
  190.                         break;
  191.                     }
  192.                     break;
  193.                 case 2:
  194.                     switch (inputdata[i]) {
  195.                     case '0':
  196.                         number3.push_back(0);
  197.                         break;
  198.                     case '1':
  199.                         number3.push_back(1);
  200.                         break;
  201.                     case '2':
  202.                         number3.push_back(2);
  203.                         break;
  204.                     case '3':
  205.                         number3.push_back(3);
  206.                         break;
  207.                     case '4':
  208.                         number3.push_back(4);
  209.                         break;
  210.                     case '5':
  211.                         number3.push_back(5);
  212.                         break;
  213.                     case '6':
  214.                         number3.push_back(6);
  215.                         break;
  216.                     case '7':
  217.                         number3.push_back(7);
  218.                         break;
  219.                     case '8':
  220.                         number3.push_back(8);
  221.                         break;
  222.                     case '9':
  223.                         number3.push_back(9);
  224.                         break;
  225.                     }
  226.                     break;
  227.                 }
  228.             } else if (inputdata[i - 1] != ' ' && inputdata[i - 1] != ',' && inputdata[i - 1] != '\n') flag++;
  229.         }
  230.         //00000000000000000//
  231.         flag = 0;
  232.         while (flag != 3) {
  233.             int rezult = 0;
  234.             switch (flag++) {
  235.             case 0:
  236.                 for (int i = 0; i < number.size(); i++) {
  237.                     rezult += number[i] * (pow((number.size() - 1) - i));
  238.                 }
  239.                 allrazv[iteraq]._A = rezult;
  240.                 break;
  241.             case 1:
  242.                 for (int i = 0; i < number2.size(); i++) {
  243.                     rezult += number2[i] * (pow((number2.size() - 1) - i));
  244.                 }
  245.                 allrazv[iteraq]._B = rezult;
  246.                 break;
  247.             case 2:
  248.                 for (int i = 0; i < number3.size(); i++) {
  249.                     rezult += number3[i] * (pow((number3.size() - 1) - i));
  250.                 }
  251.                 allrazv[iteraq].dlina = rezult;
  252.                 break;
  253.             }
  254.         }
  255.     }
  256.     //0000000000000//
  257.     string tempostring = "a";
  258.     allrazv[0].left.historylal.push_back(razvilka::core(tempostring,allrazv[0]._A));
  259.     tempostring = { 'b','d'};
  260.     allrazv[0].left.historylal.push_back(razvilka::core(tempostring, allrazv[0]._B + allrazv[0].dlina));
  261.     tempostring = { 'b' };
  262.     allrazv[0].right.historylal.push_back(razvilka::core(tempostring, allrazv[0]._B));
  263.     tempostring = { 'a', 'd' };
  264.     allrazv[0].right.historylal.push_back(razvilka::core(tempostring, allrazv[0]._A + allrazv[0].dlina));
  265.  
  266.     int aboba = 0;
  267.     while (++aboba < N) {
  268.         allrazv[aboba].makehistorylal_forleft(allrazv[aboba - 1], 1 );
  269.         allrazv[aboba].makehistorylal_forleft(allrazv[aboba - 1], 0 );
  270.         allrazv[aboba].makehistorylal_forright(allrazv[aboba - 1], 1);
  271.         allrazv[aboba].makehistorylal_forright(allrazv[aboba - 1], 0);
  272.     }
  273.     //00000000000000//
  274.     pair<int, string> leftmost(9999999999," ");
  275.     pair<int, string> rightmost(9999999999, " ");
  276.     for (int i = 0; i < allrazv[N - 1].left.historylal.size(); i++) {
  277.         if (allrazv[N - 1].left.historylal[i].dlina_path < leftmost.first) {
  278.             leftmost.first = allrazv[N - 1].left.historylal[i].dlina_path;
  279.             leftmost.second = allrazv[N - 1].left.historylal[i].path;
  280.         }
  281.     }
  282.     for (int i = 0; i < allrazv[N - 1].right.historylal.size(); i++) {
  283.         if (allrazv[N - 1].right.historylal[i].dlina_path < rightmost.first) {
  284.             rightmost.first = allrazv[N - 1].right.historylal[i].dlina_path;
  285.             rightmost.second = allrazv[N - 1].right.historylal[i].path;
  286.         }
  287.     }
  288.     pair<int, string> themosteffectivemethodofsolutionthisproblem;
  289.     if (leftmost.first < rightmost.first) {
  290.         themosteffectivemethodofsolutionthisproblem.first = leftmost.first;
  291.         themosteffectivemethodofsolutionthisproblem.second = leftmost.second;
  292.     } else {
  293.         themosteffectivemethodofsolutionthisproblem.first = rightmost.first;
  294.         themosteffectivemethodofsolutionthisproblem.second = rightmost.second;
  295.     }
  296.     cout << endl << themosteffectivemethodofsolutionthisproblem.second << endl;
  297.     return 0;
  298. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement