Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include<fstream>
- #include<iomanip>
- using namespace std;
- int main()
- {
- ifstream in("input.txt");
- ofstream out("output.txt");
- char x;
- int q = 1;
- int c = 0;
- if (!in)
- {
- cout << "Cant open file" << endl;
- exit(-1);
- }
- while (in >> x && q != 4)
- {
- out << x << setw(6);
- switch (q)
- {
- case 1:
- if (x == 'Y')
- {
- q = 1;
- out << 1;
- c++;
- }
- else if (x == 'A')
- {
- q = 3;
- out << 7;
- }
- else if (x == 'B')
- {
- q = 2;
- out << 4;
- }
- else
- {
- q = 4;
- out << "error";
- }
- break;
- case 2:
- if (x == 'Y')
- {
- q = 1;
- out << 1;
- }
- else if (x == 'B')
- {
- q = 3;
- out << 4;
- }
- else if (x == 'A')
- {
- q = 3;
- out << 4;
- }
- else
- {
- q = 4;
- out << "error";
- }
- break;
- case 3:
- if (x == 'A')
- {
- q = 3;
- out << 7;
- }
- else if (x == 'B')
- {
- q = 3;
- out << 1;
- }
- else if (x == 'Y')
- {
- q = 1;
- out << 1;
- }
- else
- {
- q = 4;
- out << "error";
- }
- break;
- default: q = 4; break;
- }
- out << setw(6) << "q=" << q << endl;
- }
- out << endl;
- out << "c=" << c;
- in.close();
- out.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement