Advertisement
Neveles

Untitled

Nov 4th, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. const int SIZE = 1000;
  7. const string ERROR_NOT_OPEN = "File isn't open!";
  8.  
  9. bool isExpression(char** str);
  10. bool isMantissa(char** str);
  11. bool isOrder(char** str);
  12. bool isUnsignedInteger(char** str);
  13. bool isNumber(char** str);
  14. bool isSign(char** str);
  15.  
  16. bool isExpression(char** str)
  17. {
  18. isSign(str);
  19. if (isMantissa(str))
  20. if (isOrder(str))
  21. return true;
  22.  
  23. return false;
  24. }
  25.  
  26. bool isMantissa(char** str)
  27. {
  28. isUnsignedInteger(str);
  29. if (**str == '.')
  30. {
  31. (*str)++;
  32. if (isUnsignedInteger(str))
  33. return true;
  34. }
  35.  
  36. return false;
  37. }
  38.  
  39. bool isOrder(char** str)
  40. {
  41. if (**str == 'E' || **str == 'e')
  42. {
  43. (*str)++;
  44. if (isSign(str))
  45. if (isUnsignedInteger(str))
  46. return true;
  47. }
  48.  
  49. return false;
  50. }
  51.  
  52. bool isUnsignedInteger(char** str)
  53. {
  54. if (isNumber(str))
  55. {
  56. isUnsignedInteger(str);
  57. return true;
  58. }
  59.  
  60. return false;
  61. }
  62.  
  63. bool isNumber(char** str)
  64. {
  65. if (**str >= '0' && **str <= '9')
  66. {
  67. (*str)++;
  68. return true;
  69. }
  70.  
  71. return false;
  72. }
  73.  
  74. bool isSign(char** str)
  75. {
  76. if ((**str == '-') || (**str == '+'))
  77. {
  78. (*str)++;
  79. return true;
  80. }
  81.  
  82. return false;
  83. }
  84.  
  85. int main()
  86. {
  87. setlocale(LC_ALL, "rus");
  88.  
  89. try
  90. {
  91. fstream input;
  92. input.open("input.txt");
  93. if (!input)
  94. throw ERROR_NOT_OPEN;
  95.  
  96. while (!input.eof())
  97. {
  98. char* str = new char[SIZE + 1];
  99. input.getline(str, SIZE + 1);
  100. char* str1 = str;
  101. bool answer = isExpression(&str);
  102.  
  103. if (answer && str[0] != '\0')
  104. {
  105. answer = false;
  106. }
  107. if (answer)
  108. cout << "Yep" << endl;
  109. else
  110. cout << "Np" << endl;
  111. str = str1;
  112.  
  113. delete[] str;
  114. }
  115.  
  116. input.close();
  117.  
  118. return 0;
  119. }
  120. catch (const string& errorS)
  121. {
  122. cerr << endl << errorS << endl;
  123. return -1;
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement