Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool log_vur() {
  5. string str = "";
  6. while (str != "or" && str!= "false" && str!= "and" && str !="true" && str != "not" ) {
  7. char ch;
  8. cin >> ch;
  9. str += ch;
  10. if (str.size() > 5) throw runtime_error("error");
  11. }
  12. if (str == "true") return 1;
  13. if (str == "false") return 0;
  14. if (str == "not") return !log_vur();
  15. if (str == "and" || str == "or") {
  16. char skobka ;
  17. cin >> skobka;
  18. if (skobka != '(') throw runtime_error("error");
  19. bool a = log_vur();
  20. char zapaytaay;
  21. cin >> zapaytaay;
  22. while (zapaytaay != ')') {
  23. if (zapaytaay != ',') throw runtime_error("error");
  24. if (str == "and") a = log_vur() && a;
  25. if (str == "or") a = log_vur() || a;
  26. cin >> zapaytaay;
  27.  
  28. }
  29. return a;
  30. }
  31. throw runtime_error("error");
  32. }
  33.  
  34. int main() {
  35. try {
  36. cout << (log_vur()?"TRUE":"FALSE") << endl;
  37. } catch (runtime_error err) {
  38. cout << err.what() << endl;
  39. }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement