Advertisement
SkeptaProgrammer

Untitled

Nov 14th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.53 KB | None | 0 0
  1. // blyadishev4444.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
  2. //вывести присвоение целочисленной хуеты
  3. #include "pch.h"
  4. #include <fstream>
  5. #include <iostream>
  6. #include <string>
  7. #include <sstream>
  8. #include <cctype>
  9. using namespace std;
  10.  // C:\onlyformydoggers\h.txt
  11. bool isConst(string str)
  12. {
  13.     bool checkConst = true;
  14.     if (isdigit(str[0]))
  15.     {
  16.         for (int i = 0; i < str.length() && checkConst; i++)
  17.             if (!(isdigit(str[i]))) checkConst = false;
  18.         if (checkConst) return true;
  19.         else return false;
  20.     }
  21.     else checkConst = false;
  22.     return checkConst;
  23. }
  24.  
  25. bool isVariable(string str)
  26. {
  27.     ifstream resFile;
  28.     resFile.open("C:\\onlyformydoggers\\more than words.txt");
  29.  
  30.     string tempStr = "";
  31.     bool isVar = true;
  32.     if (isConst(str))
  33.         return false;
  34.     else return true;
  35.     while (!resFile.eof() && isVar)
  36.     {
  37.         resFile >> tempStr;
  38.         if (str == tempStr) isVar = false;
  39.     }
  40.     for (int i = 0; i < str.length() && isVar; i++)
  41.         if (str[i] >= 58 && str[i] <= 64 || str[i] >= 0 && str[i] <= 47 || str[i] >= 91 && str[i] < 95 || str[i] == 96 || str[i] >= 123) isVar = false; // можно исправить с функцией из cctype, там на определенние является символом, но не является буквой или цфрой
  42.     resFile.close();
  43.     return isVar;
  44. }
  45.  
  46.  
  47.  
  48. bool isSymbols(string str)
  49. {
  50.     return str.find("=") != -1;
  51. }
  52.  
  53. string getString(string &s)
  54. {
  55.     ifstream workFile;
  56.     string result = "", str = "";
  57.     //getline(cin, s);
  58.     workFile.open(s);
  59.     while (!workFile.eof())
  60.     {
  61.         getline(workFile, str);
  62.         result += str + " ";
  63.         str = "";
  64.     }
  65.     workFile.close();
  66.     return result+=";";
  67. }
  68.  
  69. enum states { START, CONST,NEXT_ADDEND,CLEAR, OPERATION_MARK, SKIP};
  70.  
  71.  
  72. int main()
  73.  {
  74.     //ifstream workFile;
  75.     string str = "", resultString = "", word = "",path="";
  76.     cin >> path;
  77.     str = getString(path);
  78.     //workFile.open(path);
  79.     //cout << workFile.is_open();
  80.     states state = START;
  81.     while (!str.empty())
  82.     {
  83.         int k = 1;
  84.         bool loop = true;
  85.         //getline(workFile, str);
  86.         while (loop)
  87.         {
  88.             switch (state)
  89.             {
  90.             case START:
  91.             {
  92.                 if (!str.empty() && isSymbols(str) &&k>0)
  93.                 {
  94.                     k = str.find("=");
  95.                     if (k>0)
  96.                     k--;
  97.                     else state = SKIP;
  98.                     while (isspace(str[k]) && k > 0) k--;
  99.                     while (k >= 0 && isalnum(str[k]))
  100.                     {
  101.                         word += str[k];
  102.                         k--;
  103.                     }
  104.                     if (word.empty()) state = SKIP;
  105.                     else
  106.                     {
  107.                         reverse(word.begin(), word.end());
  108.                         if (isVariable(word))
  109.                         {
  110.                             resultString += word + " = ";
  111.                             word = "";
  112.                             state = CONST;
  113.                         }
  114.                         else
  115.                         {
  116.                             str.erase(0, str.find("=") + 1);
  117.                             state = START;
  118.                             resultString = "";
  119.                         }
  120.                         break;
  121.                     }
  122.                 }
  123.                 else state = SKIP;
  124.                
  125.                 break;
  126.             }
  127.             case CONST:
  128.             {
  129.                 k = str.find("=");
  130.                 k++;
  131.                 while (isspace(str[k]) && k < str.length()) k++;
  132.                 while (k < str.length() && isalnum(str[k]))
  133.                 {
  134.                     word += str[k];
  135.                     k++;
  136.                 }
  137.                 //reverse(word.begin(), word.end());
  138.                 if (isConst(word)&&!word.empty())
  139.                 {
  140.                     state = CLEAR;
  141.                     resultString += word;
  142.                     cout << resultString << "\n";
  143.                     str.erase(0, k);
  144.  
  145.                 }
  146.                 else state = SKIP;
  147.             }
  148.             break;
  149.             case CLEAR:
  150.             {
  151.                 word = "";
  152.                 resultString = "";
  153.                 state = START;
  154.             }
  155.             break;
  156.             /*
  157.             case OPERATION_MARK:
  158.             {
  159.                 while (isspace(str[k]))
  160.                     k++;
  161.  
  162.                 if ((str[k] == '+' || str[k] == '-'))
  163.                 {
  164.                     state = NEXT_ADDEND;
  165.                     if (str[k] == '+')
  166.                         resultString += " + ";
  167.                     else resultString += " - ";
  168.                 }
  169.                 else
  170.                 {
  171.                     str.erase(0, k);    //str.find(resultString.erase(resultString.find(" ")+1, resultString.length())));
  172.                     state = CLEAR;
  173.                    
  174.                 }
  175.             }
  176.             break;
  177.             case NEXT_ADDEND:
  178.             {
  179.                 word = "";
  180.                 k++;
  181.                 while (isspace(str[k]) && k < str.length()) k++;
  182.                 while (isalnum(str[k]) && k < str.length())
  183.                 {
  184.                     word += str[k];
  185.                     k++;
  186.                 }
  187.                 if (isVariable(word))
  188.                 {
  189.                     resultString += word;
  190.                     cout << resultString << "\n";
  191.                     state = CLEAR;
  192.                     str.erase(0, k);
  193.  
  194.                 }
  195.                 else state = SKIP;
  196.             }
  197.             break;
  198.             //*/
  199.             case SKIP:
  200.             {
  201.                 word = "";
  202.                 resultString = "";
  203.                 loop = false;
  204.                 if (k<str.length()&&isSymbols(str))
  205.                 str.erase(0, str.find("=")+1);// str.find(";") + 1);
  206.                 else str = "";
  207.                 state = START;
  208.             }
  209.             break;
  210.  
  211.             }
  212.         }
  213.     }
  214.     workFile.close();
  215.     return 0;
  216. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement