Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // syrykh_4.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
- // split
- #include "pch.h"
- #include <fstream>
- #include <iostream>
- #include <string>
- #include <sstream>
- using namespace std;
- bool operationMark(string str)
- {
- return (str == ">=" || str == "<=" || str == "==" || str == "<" || str == ">" || str == "!=");
- }
- bool checkVariableIdentifcator(string str)
- {
- ifstream resFile;
- resFile.open("C:\\onlyformydoggers\\more than words.txt");
- string tempStr="";
- bool checkConst = true, isVar = true;
- if (str[0] >= 48 && str[0] <= 57)
- {
- for (int i = 0; i < str.length() && checkConst; i++)
- if (!(str[i] <= 57 && str[i] >= 48)) checkConst = false;
- if (checkConst) return true;
- else return false;
- }
- 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] <= 96 || str[i] >= 123) isVar = false;
- resFile.close();
- return isVar;
- }
- enum states {START, IDENTIFICATOR, OPERATION_MARK, SUCCESS, SKIP};
- int main()
- {
- ifstream resourceFile,workFile;
- string str = "", word="";
- bool success = false, globalSuccess = true;
- workFile.open("C:\\onlyformydoggers\\conditional strings.txt");
- states state = START;
- while (!workFile.eof())
- {
- getline(workFile, str);
- istringstream streamStr(str);
- globalSuccess = true;
- state = START;
- for (int j = 0; j < 3 && globalSuccess; j++)
- {
- success = false;
- streamStr >> word;
- while(!success && globalSuccess)
- {
- switch (state)
- {
- case START:
- if (word[0] == '<' || word[0] == '>' || word[0] == '!' || word[0] == '=') state = OPERATION_MARK;
- else state = IDENTIFICATOR;
- break;
- case IDENTIFICATOR:
- if (checkVariableIdentifcator(word)) state = SUCCESS;
- else state = SKIP;
- break;
- case OPERATION_MARK: if (operationMark(word)) state = SUCCESS;
- else state = SKIP;
- break;
- case SKIP: globalSuccess = false;
- break;
- case SUCCESS: success = true;
- break;
- }
- }
- }
- if (globalSuccess) cout << str << '\n';
- }
- workFile.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement