Advertisement
Guest User

кугур

a guest
Mar 18th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 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. if (!in)
  13. {
  14. cout << "Cant open file" << endl;
  15. exit(-1);
  16. }
  17. while (in >> x && q != 7)
  18. {
  19. out << x;
  20.  
  21. switch (q)
  22. {
  23. case 1:
  24. if ( x == '-')
  25. {
  26. q = 1;
  27. out << 2 << " " ;
  28. }
  29. else if (x == '+')
  30. {
  31. q = 2;
  32. out << 0<< " " ;
  33.  
  34. }
  35.  
  36. else
  37. q = 7;
  38. break;
  39. case 2:
  40. if (x == '-')
  41. {
  42. q = 1;
  43. out << 1<< " " ;
  44. }
  45. else if (x == '+')
  46. {
  47. q = 4;
  48. out << 2<< " " ;
  49. }
  50. else
  51. q = 7;
  52. break;
  53. case 3:
  54. if (x == '+')
  55. {
  56. q = 2;
  57. out << 0 << " " ;
  58. }
  59. else if (x == '-')
  60. {
  61. q = 4;
  62. out << 4 << " " ;
  63. }
  64.  
  65. else
  66. q = 7;
  67. break;
  68. case 4:
  69. if (x == '-')
  70. {
  71. q = 4;
  72. out << 1 << " ";
  73. }
  74. else if (x == '+')
  75. {
  76. q = 5;
  77. out << 1 <<" ";
  78. }
  79. else
  80. q = 7;
  81. break;
  82. case 5:
  83. if (x == '+')
  84. {
  85. q = 6;
  86. out << 0 <<" ";
  87. }
  88. else if (x == '-')
  89. {
  90.  
  91. q = 6;
  92. out << 4 << " ";
  93. }
  94. else
  95. q = 7;
  96. break;
  97. case 6:
  98. if (x == '-')
  99. {
  100. q = 6;
  101. out << 2 <<" ";
  102.  
  103. }
  104. else if (x == '+')
  105. {
  106. q = 4;
  107. out << 3<<" ";
  108. }
  109. else
  110. q = 7;
  111. break;
  112. default: q = 7; break;
  113.  
  114. }
  115. out << setw(2) << "q=" <<q<< endl;
  116. }
  117. out << endl;
  118. in.close();
  119. out.close();
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement