Advertisement
SkeptaProgrammer

Untitled

Nov 16th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 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,CLEAR, 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. if (isConst(word)&&!word.empty())
  138. {
  139. state = CLEAR;
  140. resultString += word;
  141. cout << resultString << "\n";
  142. str.erase(0, k);
  143.  
  144. }
  145. else state = SKIP;
  146. }
  147. break;
  148. case CLEAR:
  149. {
  150. word = "";
  151. resultString = "";
  152. state = START;
  153. }
  154. break;
  155. case SKIP:
  156. {
  157. word = "";
  158. resultString = "";
  159. loop = false;
  160. if (k<str.length()&&isSymbols(str))
  161. str.erase(0, str.find("=")+1);// str.find(";") + 1);
  162. else str = "";
  163. state = START;
  164. }
  165. break;
  166.  
  167. }
  168. }
  169. }
  170. //workFile.close();
  171. return 0;
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement