Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // blyadishev4444.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
- //вывести присвоение целочисленной хуеты
- #include "pch.h"
- #include <fstream>
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <cctype>
- using namespace std;
- // C:\onlyformydoggers\h.txt
- bool isConst(string str)
- {
- bool checkConst = true;
- if (isdigit(str[0]))
- {
- for (int i = 0; i < str.length() && checkConst; i++)
- if (!(isdigit(str[i]))) checkConst = false;
- if (checkConst) return true;
- else return false;
- }
- else checkConst = false;
- return checkConst;
- }
- bool isVariable(string str)
- {
- ifstream resFile;
- resFile.open("C:\\onlyformydoggers\\more than words.txt");
- string tempStr = "";
- bool isVar = true;
- if (isConst(str))
- return false;
- else return true;
- while (!resFile.eof() && isVar)
- {
- resFile >> tempStr;
- if (str == tempStr) isVar = false;
- }
- for (int i = 0; i < str.length() && isVar; i++)
- 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, там на определенние является символом, но не является буквой или цфрой
- resFile.close();
- return isVar;
- }
- bool isSymbols(string str)
- {
- return str.find("=") != -1;
- }
- string getString(string &s)
- {
- ifstream workFile;
- string result = "", str = "";
- //getline(cin, s);
- workFile.open(s);
- while (!workFile.eof())
- {
- getline(workFile, str);
- result += str + " ";
- str = "";
- }
- workFile.close();
- return result+=";";
- }
- enum states { START, CONST,NEXT_ADDEND,CLEAR, OPERATION_MARK, SKIP};
- int main()
- {
- //ifstream workFile;
- string str = "", resultString = "", word = "",path="";
- cin >> path;
- str = getString(path);
- //workFile.open(path);
- //cout << workFile.is_open();
- states state = START;
- while (!str.empty())
- {
- int k = 1;
- bool loop = true;
- //getline(workFile, str);
- while (loop)
- {
- switch (state)
- {
- case START:
- {
- if (!str.empty() && isSymbols(str) &&k>0)
- {
- k = str.find("=");
- if (k>0)
- k--;
- else state = SKIP;
- while (isspace(str[k]) && k > 0) k--;
- while (k >= 0 && isalnum(str[k]))
- {
- word += str[k];
- k--;
- }
- if (word.empty()) state = SKIP;
- else
- {
- reverse(word.begin(), word.end());
- if (isVariable(word))
- {
- resultString += word + " = ";
- word = "";
- state = CONST;
- }
- else
- {
- str.erase(0, str.find("=") + 1);
- state = START;
- resultString = "";
- }
- break;
- }
- }
- else state = SKIP;
- break;
- }
- case CONST:
- {
- k = str.find("=");
- k++;
- while (isspace(str[k]) && k < str.length()) k++;
- while (k < str.length() && isalnum(str[k]))
- {
- word += str[k];
- k++;
- }
- //reverse(word.begin(), word.end());
- if (isConst(word)&&!word.empty())
- {
- state = CLEAR;
- resultString += word;
- cout << resultString << "\n";
- str.erase(0, k);
- }
- else state = SKIP;
- }
- break;
- case CLEAR:
- {
- word = "";
- resultString = "";
- state = START;
- }
- break;
- /*
- case OPERATION_MARK:
- {
- while (isspace(str[k]))
- k++;
- if ((str[k] == '+' || str[k] == '-'))
- {
- state = NEXT_ADDEND;
- if (str[k] == '+')
- resultString += " + ";
- else resultString += " - ";
- }
- else
- {
- str.erase(0, k); //str.find(resultString.erase(resultString.find(" ")+1, resultString.length())));
- state = CLEAR;
- }
- }
- break;
- case NEXT_ADDEND:
- {
- word = "";
- k++;
- while (isspace(str[k]) && k < str.length()) k++;
- while (isalnum(str[k]) && k < str.length())
- {
- word += str[k];
- k++;
- }
- if (isVariable(word))
- {
- resultString += word;
- cout << resultString << "\n";
- state = CLEAR;
- str.erase(0, k);
- }
- else state = SKIP;
- }
- break;
- //*/
- case SKIP:
- {
- word = "";
- resultString = "";
- loop = false;
- if (k<str.length()&&isSymbols(str))
- str.erase(0, str.find("=")+1);// str.find(";") + 1);
- else str = "";
- state = START;
- }
- break;
- }
- }
- }
- workFile.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement