Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- bool log_vur() {
- string str = "";
- while (str != "or" && str!= "false" && str!= "and" && str !="true" && str != "not" ) {
- char ch;
- cin >> ch;
- str += ch;
- if (str.size() > 5) throw runtime_error("error");
- }
- if (str == "true") return 1;
- if (str == "false") return 0;
- if (str == "not") return !log_vur();
- if (str == "and" || str == "or") {
- char skobka ;
- cin >> skobka;
- if (skobka != '(') throw runtime_error("error");
- bool a = log_vur();
- char zapaytaay;
- cin >> zapaytaay;
- while (zapaytaay != ')') {
- if (zapaytaay != ',') throw runtime_error("error");
- if (str == "and") a = log_vur() && a;
- if (str == "or") a = log_vur() || a;
- cin >> zapaytaay;
- }
- return a;
- }
- throw runtime_error("error");
- }
- int main() {
- try {
- cout << (log_vur()?"TRUE":"FALSE") << endl;
- } catch (runtime_error err) {
- cout << err.what() << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement