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;
- if (!in)
- {
- cout << "Cant open file" << endl;
- exit(-1);
- }
- while (in >> x && q != 7)
- {
- out << x;
- switch (q)
- {
- case 1:
- if ( x == '-')
- {
- q = 1;
- out << 2 << " " ;
- }
- else if (x == '+')
- {
- q = 2;
- out << 0<< " " ;
- }
- else
- q = 7;
- break;
- case 2:
- if (x == '-')
- {
- q = 1;
- out << 1<< " " ;
- }
- else if (x == '+')
- {
- q = 4;
- out << 2<< " " ;
- }
- else
- q = 7;
- break;
- case 3:
- if (x == '+')
- {
- q = 2;
- out << 0 << " " ;
- }
- else if (x == '-')
- {
- q = 4;
- out << 4 << " " ;
- }
- else
- q = 7;
- break;
- case 4:
- if (x == '-')
- {
- q = 4;
- out << 1 << " ";
- }
- else if (x == '+')
- {
- q = 5;
- out << 1 <<" ";
- }
- else
- q = 7;
- break;
- case 5:
- if (x == '+')
- {
- q = 6;
- out << 0 <<" ";
- }
- else if (x == '-')
- {
- q = 6;
- out << 4 << " ";
- }
- else
- q = 7;
- break;
- case 6:
- if (x == '-')
- {
- q = 6;
- out << 2 <<" ";
- }
- else if (x == '+')
- {
- q = 4;
- out << 3<<" ";
- }
- else
- q = 7;
- break;
- default: q = 7; break;
- }
- out << setw(2) << "q=" <<q<< endl;
- }
- out << endl;
- in.close();
- out.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement