Advertisement
SkeptaProgrammer

Untitled

Apr 28th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. // syrykh_4.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
  2. // split
  3.  
  4. #include "pch.h"
  5. #include <fstream>
  6. #include <iostream>
  7. #include <string>
  8. #include <sstream>
  9. using namespace std;
  10.  
  11. bool operationMark(string str)
  12. {
  13. return (str == ">=" || str == "<=" || str == "==" || str == "<" || str == ">" || str == "!=");
  14. }
  15.  
  16. bool checkVariableIdentifcator(string str)
  17. {
  18. ifstream resFile;
  19. resFile.open("C:\\onlyformydoggers\\more than words.txt");
  20.  
  21. string tempStr="";
  22. bool checkConst = true, isVar = true;
  23. if (str[0] >= 48 && str[0] <= 57)
  24. {
  25. for (int i = 0; i < str.length() && checkConst; i++)
  26. if (!(str[i] <= 57 && str[i] >= 48)) checkConst = false;
  27. if (checkConst) return true;
  28. else return false;
  29. }
  30.  
  31. while (!resFile.eof()&& isVar)
  32. {
  33. resFile >> tempStr;
  34. if (str == tempStr) isVar = false;
  35. }
  36. for (int i = 0; i < str.length()&& isVar; i++)
  37. if (str[i] >= 58 && str[i] <= 64 || str[i] >= 0 && str[i] <= 47 || str[i] >= 91 && str[i] <= 96 || str[i] >= 123) isVar = false;
  38.  
  39. resFile.close();
  40. return isVar;
  41. }
  42.  
  43.  
  44. enum states {START, IDENTIFICATOR, OPERATION_MARK, SUCCESS, SKIP};
  45.  
  46. int main()
  47. {
  48. ifstream resourceFile,workFile;
  49. string str = "", word="";
  50. bool success = false, globalSuccess = true;
  51. workFile.open("C:\\onlyformydoggers\\conditional strings.txt");
  52. states state = START;
  53. while (!workFile.eof())
  54. {
  55. getline(workFile, str);
  56. istringstream streamStr(str);
  57. globalSuccess = true;
  58. state = START;
  59. for (int j = 0; j < 3 && globalSuccess; j++)
  60. {
  61. success = false;
  62. streamStr >> word;
  63. while(!success && globalSuccess)
  64. {
  65. switch (state)
  66. {
  67. case START:
  68. if (word[0] == '<' || word[0] == '>' || word[0] == '!' || word[0] == '=') state = OPERATION_MARK;
  69. else state = IDENTIFICATOR;
  70. break;
  71. case IDENTIFICATOR:
  72. if (checkVariableIdentifcator(word)) state = SUCCESS;
  73. else state = SKIP;
  74. break;
  75. case OPERATION_MARK: if (operationMark(word)) state = SUCCESS;
  76. else state = SKIP;
  77. break;
  78. case SKIP: globalSuccess = false;
  79. break;
  80. case SUCCESS: success = true;
  81. break;
  82. }
  83. }
  84. }
  85. if (globalSuccess) cout << str << '\n';
  86. }
  87. workFile.close();
  88. return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement