Advertisement
Guest User

Untitled

a guest
May 24th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. /*
  2. S -> BAC
  3. B -> w
  4. A -> qA | q
  5. C -> S | l
  6. */
  7.  
  8. #include <iostream>
  9. #include <stdexcept>
  10.  
  11. using namespace std;
  12.  
  13. int c;
  14.  
  15. void gc() {
  16. c = getchar();
  17. }
  18.  
  19. void B() {
  20. if (c != 'w') {
  21. throw runtime_error("B failed");
  22. }
  23. gc(); // потому что проверили терминал
  24. }
  25.  
  26. void A() {
  27. if (c != 'q') {
  28. throw runtime_error("A failed");
  29. }
  30. gc();
  31. while (c == 'q') {
  32. gc();
  33. }
  34. }
  35.  
  36. void S(); // обязательно декларировать перед C, чтобы использовать ее в C, потому что C используется в S, а S в C
  37. void C() {
  38. if (c == 'l') {
  39. gc();
  40. return;
  41. }
  42.  
  43. if (c == 'w') {
  44. S();
  45. return;
  46. }
  47.  
  48. throw runtime_error("C failed");
  49. }
  50.  
  51. void S() {
  52. B();
  53. A();
  54. C();
  55. }
  56.  
  57. int main() {
  58. try {
  59. gc(); // считываем первый символ и покрутились
  60. S();
  61. cout << "YES" << endl;
  62. } catch (runtime_error ex) {
  63. cout << "NO: " << ex.what() << endl;
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement