Advertisement
SkeptaProgrammer

Untitled

Jun 23rd, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.01 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.  
  11. bool isVariable(string str)
  12. {
  13.     ifstream resFile;
  14.     resFile.open("C:\\onlyformydoggers\\more than words.txt");
  15.  
  16.     string tempStr = "";
  17.     bool checkConst = true, isVar = true;
  18.     if (str[0] >= 48 && str[0] <= 57)
  19.     {
  20.         for (int i = 0; i < str.length() && checkConst; i++)
  21.             if (!(isdigit(str[i]))) checkConst = false;
  22.         if (checkConst) return true;
  23.         else return false;
  24.     }
  25.  
  26.     while (!resFile.eof() && isVar)
  27.     {
  28.         resFile >> tempStr;
  29.         if (str == tempStr) isVar = false;
  30.     }
  31.     for (int i = 0; i < str.length() && isVar; i++)
  32.         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;
  33.  
  34.     resFile.close();
  35.     return isVar;
  36. }
  37.  
  38. bool isSymbols(string str)
  39. {
  40.     return str.find("=") != -1 && str.find(";") != -1;
  41. }
  42. string getString(string &s)
  43. {
  44.     ifstream workFile;
  45.     string result = "", str = "";
  46.     getline(cin, s);
  47.     workFile.open(s);
  48.     while (!workFile.eof())
  49.     {
  50.         getline(workFile, str);
  51.         result += str + " ";
  52.         str = "";
  53.     }
  54.     workFile.close();
  55.     return result+=";";
  56. }
  57.  
  58. enum states { START, ADDEND,NEXT_ADDEND,CLEAR, OPERATION_MARK, SKIP};
  59.  
  60.  
  61. int main()
  62. {
  63.     //ifstream workFile;
  64.     string str = "", resultString = "", word = "",path="";
  65.     str = getString(path);
  66.     //workFile.open(path);
  67.     //cout << workFile.is_open();
  68.     states state = START;
  69.     while (!str.empty())
  70.     {
  71.         int k = 0;
  72.         bool loop = true;
  73.         //getline(workFile, str);
  74.         while (loop)
  75.         {
  76.             switch (state)
  77.             {
  78.             case START:
  79.             {
  80.                 if (!str.empty()&&isSymbols(str))
  81.                 {
  82.                     k = str.find("=");
  83.                     k--;
  84.                     while (isspace(str[k]) && k > 0) k--;
  85.                     while (k >= 0 && isalnum(str[k]))
  86.                     {
  87.                         word += str[k];
  88.                         k--;
  89.                     }
  90.                     reverse(word.begin(), word.end());
  91.                     if (isVariable(word))
  92.                     {
  93.                         resultString += word + " = ";
  94.                         word = "";
  95.                         state = ADDEND;
  96.                     }
  97.                     else
  98.                     {
  99.                         str.erase(0, str.find("="));
  100.                         state = START;
  101.                         resultString = "";
  102.                     }
  103.                     break;
  104.                 }
  105.                 else state = SKIP;
  106.                 break;
  107.             }
  108.             case ADDEND:
  109.             {
  110.                 k = str.find("=");
  111.                 k++;
  112.                 while (isspace(str[k]) && k < str.length()) k++;
  113.                 while (k < str.length() && isalnum(str[k]))
  114.                 {
  115.                     word += str[k];
  116.                     k++;
  117.                 }
  118.                 //reverse(word.begin(), word.end());
  119.                 if (isVariable(word))
  120.                 {
  121.                     state = OPERATION_MARK;
  122.                     resultString += word;
  123.                     //word = "";
  124.  
  125.                 }
  126.                 else
  127.                 {
  128.                     word = "";
  129.                     str.erase(0, str.find("="));
  130.                     state = START;
  131.                     resultString = "";
  132.  
  133.                 }
  134.             }
  135.             break;
  136.             case CLEAR:
  137.             {
  138.                 word = "";
  139.                 resultString = "";
  140.                 state = START;
  141.             }
  142.             break;
  143.             case OPERATION_MARK:
  144.             {
  145.                 int raznost = 0, i = k;
  146.                 if (isspace(str[k]))
  147.                     while (isspace(str[k]))
  148.                     {
  149.                         k++;
  150.                         raznost++;
  151.                     }
  152.  
  153.                 if ((str[k] == '+' || str[k] == '-'))
  154.                 {
  155.                     state = NEXT_ADDEND;
  156.                     if (str[k] == '+')
  157.                         resultString += " + ";
  158.                     else resultString += " - ";
  159.                 }
  160.                 else
  161.                 {
  162.                     str.erase(0, str.find(word));
  163.                     state = START;
  164.                     resultString = "";
  165.                 }
  166.             }
  167.             break;
  168.             case NEXT_ADDEND:
  169.             {
  170.                 word = "";
  171.                 k++;
  172.                 while (isspace(str[k]) && k < str.length()) k++;
  173.                 while (isalnum(str[k]) && k < str.length())
  174.                 {
  175.                     word += str[k];
  176.                     k++;
  177.                 }
  178.                 if (isVariable(word))
  179.                 {
  180.                     resultString += word;
  181.                     cout << resultString << "\n";
  182.                     state = CLEAR;
  183.                     str.erase(0, str.find(";") + 1);
  184.  
  185.                 }
  186.             }
  187.             break;
  188.             case SKIP:
  189.             {
  190.                 word = "";
  191.                 resultString = "";
  192.                 loop = false;
  193.                 state = START;
  194.             }
  195.             break;
  196.  
  197.             }
  198.         }
  199.     }
  200.     //workFile.close();
  201.     return 0;
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement