Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using std::cout;
  4. using std::endl;
  5. using std::cin;
  6.  
  7. void S();
  8. void A();
  9. void B();
  10.  
  11. void S()
  12. {
  13. char c;
  14. if (!(cin >> c)) {
  15. throw "fail";
  16. }
  17. if (c == '1') {
  18. A();
  19. if (!(cin >> c)) {
  20. throw "fail";
  21. }
  22. if (c != '0') {
  23. throw c;
  24. }
  25. } else {
  26. throw c;
  27. }
  28. }
  29.  
  30. void A()
  31. {
  32. char c;
  33. if (!(cin >> c)) {
  34. throw "fail";
  35. }
  36. if (c == '1') {
  37. A();
  38. if (!(cin >> c)) {
  39. throw "fail";
  40. }
  41. if (c != '0') {
  42. throw c;
  43. }
  44. } else if (c == '0') {
  45. B();
  46. if (!(cin >> c)) {
  47. throw "fail";
  48. }
  49. if (c != '1') {
  50. throw c;
  51. }
  52. } else {
  53. throw c;
  54. }
  55. }
  56.  
  57. void B()
  58. {
  59. char c;
  60. if (!(cin >> c)) {
  61. throw "fail";
  62. }
  63. if (c == '0') {
  64. B();
  65. if (!(cin >> c)) {
  66. throw "fail";
  67. }
  68. if (c != '1') {
  69. throw c;
  70. }
  71. } else {
  72. cin.putback(c);
  73. }
  74. }
  75.  
  76. int main()
  77. {
  78. while (true) {
  79. try {
  80. S();
  81. } catch (char c) {
  82. if (isspace(c)) {
  83. cout << "WIN" << endl;
  84. try {
  85. S();
  86. } catch (...) {
  87. throw;
  88. }
  89. } else {
  90. throw;
  91. }
  92. } catch (...) {
  93. cout << "FAIL" << endl;
  94. return 0;
  95. }
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement