Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- const int SIZE = 1000;
- const string ERROR_NOT_OPEN = "File isn't open!";
- bool isExpression(char** str);
- bool isMantissa(char** str);
- bool isOrder(char** str);
- bool isUnsignedInteger(char** str);
- bool isNumber(char** str);
- bool isSign(char** str);
- bool isExpression(char** str)
- {
- isSign(str);
- if (isMantissa(str))
- if (isOrder(str))
- return true;
- return false;
- }
- bool isMantissa(char** str)
- {
- isUnsignedInteger(str);
- if (**str == '.')
- {
- (*str)++;
- if (isUnsignedInteger(str))
- return true;
- }
- return false;
- }
- bool isOrder(char** str)
- {
- if (**str == 'E' || **str == 'e')
- {
- (*str)++;
- if (isSign(str))
- if (isUnsignedInteger(str))
- return true;
- }
- return false;
- }
- bool isUnsignedInteger(char** str)
- {
- if (isNumber(str))
- {
- isUnsignedInteger(str);
- return true;
- }
- return false;
- }
- bool isNumber(char** str)
- {
- if (**str >= '0' && **str <= '9')
- {
- (*str)++;
- return true;
- }
- return false;
- }
- bool isSign(char** str)
- {
- if ((**str == '-') || (**str == '+'))
- {
- (*str)++;
- return true;
- }
- return false;
- }
- int main()
- {
- setlocale(LC_ALL, "rus");
- try
- {
- fstream input;
- input.open("input.txt");
- if (!input)
- throw ERROR_NOT_OPEN;
- while (!input.eof())
- {
- char* str = new char[SIZE + 1];
- input.getline(str, SIZE + 1);
- char* str1 = str;
- bool answer = isExpression(&str);
- if (answer && str[0] != '\0')
- {
- answer = false;
- }
- if (answer)
- cout << "Yep" << endl;
- else
- cout << "Np" << endl;
- str = str1;
- delete[] str;
- }
- input.close();
- return 0;
- }
- catch (const string& errorS)
- {
- cerr << endl << errorS << endl;
- return -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement