Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int pow(int step) {
- if (step < 0) return -666;
- if (step == 0) return 1;
- if (step == 1) return 10;
- return 10 * pow(--step);
- }
- struct razvilka {
- int _A;
- int _B;
- int dlina;
- struct core {
- string path;
- int dlina_path;
- core() {
- dlina_path = 0;
- }
- core(string path, int dlina_path) {
- this->path = path;
- this->dlina_path = dlina_path;
- }
- };
- struct head {
- vector<core> historylal;
- head() {
- }
- };
- head left;
- head right;
- core podbitb(const core& object, string histor, int dlin_histor) {
- core objectmy = object;
- objectmy.path += histor;
- objectmy.dlina_path += dlin_histor;
- return objectmy;
- }
- void makehistorylal_forright(const razvilka& copirka, int mode) {
- if (mode == 1) {
- for (int i = 0; i < copirka.left.historylal.size(); i++) {
- string histor = { 'a','d' };
- this->right.historylal.push_back(core(podbitb(copirka.left.historylal[i] ,histor,this->_A + this->dlina )));
- }
- for (int i = 0; i < copirka.left.historylal.size(); i++) {
- string histor = { 'd', 'b' };
- this->right.historylal.push_back(core(podbitb(copirka.left.historylal[i], histor, this->_B + copirka.dlina)));
- }
- } else {
- for (int i = 0; i < copirka.left.historylal.size(); i++) {
- string histor = { 'd' };
- this->right.historylal.push_back(core(podbitb(copirka.right.historylal[i], histor, this->_B)));
- }
- for (int i = 0; i < copirka.left.historylal.size(); i++) {
- string histor = { 'd', 'a', 'd' };
- this->right.historylal.push_back(core(podbitb(copirka.right.historylal[i], histor, copirka.dlina + this->_A + this->dlina)));
- }
- }
- }
- void makehistorylal_forleft(const razvilka& copirka, int mode) {
- if (mode == 1) {
- for (int i = 0; i < copirka.left.historylal.size(); i++) {
- string histor = {'a'};
- this->left.historylal.push_back(core(podbitb(copirka.left.historylal[i], histor, this->_A)));
- }
- for (int i = 0; i < copirka.left.historylal.size(); i++) {
- string histor = { 'd', 'b', 'd' };
- this->left.historylal.push_back(core(podbitb(copirka.left.historylal[i], histor, copirka.dlina + this->_B + this->dlina)));
- }
- } else {
- for (int i = 0; i < copirka.left.historylal.size(); i++) {
- string histor = { 'b', 'd' };
- this->left.historylal.push_back(core(podbitb(copirka.right.historylal[i], histor, this->_B + this->dlina)));
- }
- for (int i = 0; i < copirka.left.historylal.size(); i++) {
- string histor = { 'd', 'a' };
- this->left.historylal.push_back(core(podbitb(copirka.right.historylal[i], histor, copirka.dlina + this->_A)));
- }
- }
- }
- razvilka() {
- _A = 0;
- _B = 0;
- dlina = 0;
- }
- };
- int main() {
- int N;
- cout << "enter N: ";
- cin >> N;
- cout << endl;
- //0000000000000//
- vector<razvilka> allrazv;
- for (int i = 0; i < N; i++) {
- allrazv.push_back(razvilka());
- }
- //0000000000000//
- int iteraq = -1;
- cout << "enter proprities (x for accept): " << endl;
- while (++iteraq != N) {
- string inputdata;
- char buffer = ' ';
- while (buffer != 'x') {
- inputdata.push_back(buffer);
- buffer = cin.get();
- }
- //0000000000000000//
- vector<int> number;
- vector<int> number2;
- vector<int> number3;
- int flag = 0;
- for (int i = 1; i < inputdata.size(); i++) {
- if (inputdata[i] != ' ' && inputdata[i] != ',' && inputdata[i] != '\n') {
- switch (flag) {
- case 0:
- switch (inputdata[i]) {
- case '0':
- number.push_back(0);
- break;
- case '1':
- number.push_back(1);
- break;
- case '2':
- number.push_back(2);
- break;
- case '3':
- number.push_back(3);
- break;
- case '4':
- number.push_back(4);
- break;
- case '5':
- number.push_back(5);
- break;
- case '6':
- number.push_back(6);
- break;
- case '7':
- number.push_back(7);
- break;
- case '8':
- number.push_back(8);
- break;
- case '9':
- number.push_back(9);
- break;
- }
- break;
- case 1:
- switch (inputdata[i]) {
- case '0':
- number2.push_back(0);
- break;
- case '1':
- number2.push_back(1);
- break;
- case '2':
- number2.push_back(2);
- break;
- case '3':
- number2.push_back(3);
- break;
- case '4':
- number2.push_back(4);
- break;
- case '5':
- number2.push_back(5);
- break;
- case '6':
- number2.push_back(6);
- break;
- case '7':
- number2.push_back(7);
- break;
- case '8':
- number2.push_back(8);
- break;
- case '9':
- number2.push_back(9);
- break;
- }
- break;
- case 2:
- switch (inputdata[i]) {
- case '0':
- number3.push_back(0);
- break;
- case '1':
- number3.push_back(1);
- break;
- case '2':
- number3.push_back(2);
- break;
- case '3':
- number3.push_back(3);
- break;
- case '4':
- number3.push_back(4);
- break;
- case '5':
- number3.push_back(5);
- break;
- case '6':
- number3.push_back(6);
- break;
- case '7':
- number3.push_back(7);
- break;
- case '8':
- number3.push_back(8);
- break;
- case '9':
- number3.push_back(9);
- break;
- }
- break;
- }
- } else if (inputdata[i - 1] != ' ' && inputdata[i - 1] != ',' && inputdata[i - 1] != '\n') flag++;
- }
- //00000000000000000//
- flag = 0;
- while (flag != 3) {
- int rezult = 0;
- switch (flag++) {
- case 0:
- for (int i = 0; i < number.size(); i++) {
- rezult += number[i] * (pow((number.size() - 1) - i));
- }
- allrazv[iteraq]._A = rezult;
- break;
- case 1:
- for (int i = 0; i < number2.size(); i++) {
- rezult += number2[i] * (pow((number2.size() - 1) - i));
- }
- allrazv[iteraq]._B = rezult;
- break;
- case 2:
- for (int i = 0; i < number3.size(); i++) {
- rezult += number3[i] * (pow((number3.size() - 1) - i));
- }
- allrazv[iteraq].dlina = rezult;
- break;
- }
- }
- }
- //0000000000000//
- string tempostring = "a";
- allrazv[0].left.historylal.push_back(razvilka::core(tempostring,allrazv[0]._A));
- tempostring = { 'b','d'};
- allrazv[0].left.historylal.push_back(razvilka::core(tempostring, allrazv[0]._B + allrazv[0].dlina));
- tempostring = { 'b' };
- allrazv[0].right.historylal.push_back(razvilka::core(tempostring, allrazv[0]._B));
- tempostring = { 'a', 'd' };
- allrazv[0].right.historylal.push_back(razvilka::core(tempostring, allrazv[0]._A + allrazv[0].dlina));
- int aboba = 0;
- while (++aboba < N) {
- allrazv[aboba].makehistorylal_forleft(allrazv[aboba - 1], 1 );
- allrazv[aboba].makehistorylal_forleft(allrazv[aboba - 1], 0 );
- allrazv[aboba].makehistorylal_forright(allrazv[aboba - 1], 1);
- allrazv[aboba].makehistorylal_forright(allrazv[aboba - 1], 0);
- }
- //00000000000000//
- pair<int, string> leftmost(9999999999," ");
- pair<int, string> rightmost(9999999999, " ");
- for (int i = 0; i < allrazv[N - 1].left.historylal.size(); i++) {
- if (allrazv[N - 1].left.historylal[i].dlina_path < leftmost.first) {
- leftmost.first = allrazv[N - 1].left.historylal[i].dlina_path;
- leftmost.second = allrazv[N - 1].left.historylal[i].path;
- }
- }
- for (int i = 0; i < allrazv[N - 1].right.historylal.size(); i++) {
- if (allrazv[N - 1].right.historylal[i].dlina_path < rightmost.first) {
- rightmost.first = allrazv[N - 1].right.historylal[i].dlina_path;
- rightmost.second = allrazv[N - 1].right.historylal[i].path;
- }
- }
- pair<int, string> themosteffectivemethodofsolutionthisproblem;
- if (leftmost.first < rightmost.first) {
- themosteffectivemethodofsolutionthisproblem.first = leftmost.first;
- themosteffectivemethodofsolutionthisproblem.second = leftmost.second;
- } else {
- themosteffectivemethodofsolutionthisproblem.first = rightmost.first;
- themosteffectivemethodofsolutionthisproblem.second = rightmost.second;
- }
- cout << endl << themosteffectivemethodofsolutionthisproblem.second << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement