Advertisement
Guest User

кугуууууур В

a guest
Mar 25th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include<fstream>
  4. #include<iomanip>
  5. using namespace std;
  6. int main()
  7. {
  8. ifstream in("input.txt");
  9. ofstream out("output.txt");
  10. char x;
  11. int q = 1;
  12. int c = 0;
  13. if (!in)
  14. {
  15. cout << "Cant open file" << endl;
  16. exit(-1);
  17. }
  18. while (in >> x && q != 4)
  19. {
  20.  
  21. out << x << setw(6);
  22.  
  23. switch (q)
  24. {
  25. case 1:
  26. if (x == 'Y')
  27. {
  28. q = 1;
  29. out << 1;
  30. c++;
  31. }
  32. else if (x == 'A')
  33. {
  34. q = 3;
  35. out << 7;
  36.  
  37. }
  38. else if (x == 'B')
  39. {
  40. q = 2;
  41. out << 4;
  42. }
  43.  
  44. else
  45. {
  46. q = 4;
  47. out << "error";
  48. }
  49. break;
  50.  
  51.  
  52. case 2:
  53. if (x == 'Y')
  54. {
  55. q = 1;
  56. out << 1;
  57. }
  58. else if (x == 'B')
  59. {
  60. q = 3;
  61. out << 4;
  62. }
  63. else if (x == 'A')
  64. {
  65. q = 3;
  66. out << 4;
  67. }
  68. else
  69. {
  70. q = 4;
  71. out << "error";
  72. }
  73. break;
  74. case 3:
  75.  
  76. if (x == 'A')
  77. {
  78. q = 3;
  79. out << 7;
  80. }
  81. else if (x == 'B')
  82. {
  83. q = 3;
  84. out << 1;
  85. }
  86. else if (x == 'Y')
  87. {
  88. q = 1;
  89. out << 1;
  90. }
  91.  
  92. else
  93. {
  94. q = 4;
  95. out << "error";
  96. }
  97. break;
  98.  
  99.  
  100. default: q = 4; break;
  101.  
  102. }
  103. out << setw(6) << "q=" << q << endl;
  104.  
  105. }
  106. out << endl;
  107. out << "c=" << c;
  108. in.close();
  109. out.close();
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement