Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- //3X1^2*X2^1*X3^7-2X1^1*X2^2*X3^3+S(2X1)-4C(2X1);X1^2-2X1^1+3X1^0;S(2X1)-4C(2X1)//
- using namespace std;
- int main()
- {
- char x;
- bool b = true;
- int q = 1, n;
- ifstream f("Text.txt");
- while (f.peek() != EOF && b == true)
- {
- f >> x;
- cout << x;
- switch (q)
- {
- case 1:
- if (x >= '0' && x <= '9')
- {
- q = 2;
- }
- else if (x == 'X')
- {
- q = 3;
- }
- else if (x == 'S' || x == 'C')
- {
- q = 6;
- }
- else b = false;
- break;
- case 2:
- if (x == 'X')
- {
- q = 3;
- }
- else if (x == 'S' || x == 'C')
- {
- q = 6;
- }
- else b = false;
- break;
- case 3:
- if (x >= '0' && x <= '9')
- {
- q = 4;
- }
- else b = false;
- break;
- case 4:
- if (x == '^')
- {
- q = 5;
- }
- else b = false;
- break;
- case 5:
- if (x >= '0' && x <= '9')
- {
- q = 11;
- }
- else b = false;
- break;
- case 6:
- if (x == '(')
- {
- q = 7;
- }
- else b = false;
- break;
- case 7:
- if (x >= '0' && x <= '9')
- {
- q = 8;
- }
- else b = false;
- break;
- case 8:
- if (x == 'X')
- {
- q = 9;
- }
- else b = false;
- break;
- case 9:
- if (x >= '0' && x <= '9')
- {
- q = 10;
- }
- else b = false;
- break;
- case 10:
- if (x == ')')
- {
- q = 11;
- }
- else b = false;
- break;
- case 11:
- if (x == '+' || x == '-' || x == ';')
- {
- q = 1;
- }
- else if (x == '*')
- {
- q = 2;
- }
- else b = false;
- break;
- }
- }
- cout << endl;
- if (b )
- cout << "all right!!";
- else
- cout << "error";
- cout << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment