Advertisement
rengetsu

Lygiagreti_Tiuringo_Masina

Oct 6th, 2018
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.00 KB | None | 0 0
  1. //Pavel Trostianko. Lygiagretusis Tiuringas.
  2.  
  3. #include <iostream>
  4. #include <fstream>
  5. #include <string>
  6. #include <conio.h>
  7.  
  8. using namespace std;
  9.  
  10. struct tiuring //kintamu ir funkciju sarasas
  11. {
  12.     bool check;
  13.     int len = 0, sk, nmbr;
  14.     char second[1000], third[1000], four[1000];
  15.     string first[1000], five[1000], poz, tiur;
  16.  
  17.     void Reading()
  18.     {
  19.         string selecting;
  20.         cout << nmbr << ".txt adress: ";
  21.  
  22.     start:
  23.         getline (cin, selecting);
  24.         ifstream fil(selecting.c_str());
  25.         if(fil.fail())
  26.         {
  27.             cout << "File Name Error!" << endl;
  28.             goto start;
  29.         }
  30.         fil >> sk;
  31.         fil >> tiur;
  32.  
  33.         while (fil >> first[len] >> second[len] >> third[len] >> four[len] >> five[len])
  34.         {
  35.             len++;
  36.         }
  37.  
  38.         fil.close();
  39.     }
  40.  
  41.     void Showing()
  42.     {
  43.         cout << endl;
  44.         cout << "File: " << nmbr << endl;
  45.         cout << tiur << endl;
  46.         cout << endl;
  47.  
  48.         for(int i=0;i<len;i++)
  49.         {
  50.             cout << first[i] << " " << second[i] << " " << third[i] << " " << four[i] << " " << five[i] << endl;
  51.         }
  52.     }
  53.  
  54.     void Process()
  55.     {
  56.         cout << "File number: " << nmbr << " ";
  57.         if(check==true)
  58.         {
  59.             poz = first[0];
  60.         }
  61.  
  62.         string er;
  63.  
  64.         for(int i=0;i<len;i++)
  65.             if(poz == first[i])
  66.             {
  67.               if(second[i] == tiur[sk+1])
  68.               {
  69.                   tiur[sk+1]= third[i];
  70.  
  71.                   if(four[i]=='r' || four[i]=='R')
  72.                   {
  73.                       sk++;
  74.                   }
  75.                   else
  76.                   {
  77.                       sk--;
  78.                   }
  79.                   if(sk < 0)
  80.                   {
  81.                       sk = tiur.length();
  82.                   }
  83.                   if(sk > tiur.length())
  84.                   {
  85.                       sk=0;
  86.                   }
  87.                   poz = five[i];
  88.               }
  89.             }
  90.             if(er != tiur) cout << tiur << endl;
  91.             er = tiur;
  92.     }
  93. };
  94.  
  95. int main()
  96. {
  97.     bool checking = false;
  98.     tiuring onet, twot, threet, fourt;
  99.  
  100.     onet.nmbr   = 1;
  101.     twot.nmbr   = 2;
  102.     threet.nmbr = 3;
  103.     fourt.nmbr  = 4;
  104.  
  105.     // Reading our line
  106.     onet.Reading();
  107.     twot.Reading();
  108.     threet.Reading();
  109.     fourt.Reading();
  110.  
  111.     // Showing our line
  112.     onet.Showing();
  113.     twot.Showing();
  114.     threet.Showing();
  115.     fourt.Showing();
  116.  
  117.     // Checking our line
  118.     onet.check = true;
  119.     twot.check = true;
  120.     threet.check = true;
  121.     fourt.check = true;
  122.  
  123.    if(getch()=='t')
  124.    {
  125.        checking = true;
  126.    }
  127.  
  128.    while(true)
  129.    {
  130.        onet.Process();
  131.        onet.check = false;
  132.  
  133.        twot.Process();
  134.        twot.check = false;
  135.  
  136.        threet.Process();
  137.        threet.check = false;
  138.  
  139.        fourt.Process();
  140.        fourt.check = false;
  141.  
  142.        if(checking == true)
  143.        {
  144.            getch();
  145.        }
  146.     }
  147.     return 0;
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement