The_Law

Untitled

Mar 16th, 2021
716
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. string raw;
  10. getline(cin, raw);
  11.  
  12. string symb;
  13. getline(cin, symb);
  14.  
  15. bool found_dog = false;
  16. bool found_dot = false;
  17.  
  18. int last_f = 0;
  19. int last_s = 0;
  20. int last_t = raw.size();
  21. int cnt = 0;
  22.  
  23. bool is_possible = true;
  24.  
  25. for (int i = 0; i < raw.size(); ++i) {
  26. if (raw[i] == '@') {
  27. if (found_dot)
  28. is_possible = false;
  29. else {
  30. last_f = cnt;
  31. found_dog = true;
  32. }
  33. } else if (raw[i] == '.') {
  34. last_s = cnt;
  35. found_dot = true;
  36. }
  37.  
  38. ++cnt;
  39. }
  40.  
  41. int size_of_first_part = last_f;
  42. int size_of_second_part = last_s - last_f - 1;
  43. int size_of_third_part = last_t - last_s - 1;
  44.  
  45. if (!is_possible) {
  46. cout << "Impossible";
  47. } else if (found_dog && found_dot &&
  48. size_of_first_part != 0 && size_of_second_part != 0 && size_of_third_part != 0) {
  49. cout << "Done";
  50. } else {
  51. vector<int> ans;
  52. for (int i = symb.size() - 1; i >= 0 && is_possible; --i) {
  53. if (symb[i] == '@') {
  54. if (found_dog) {
  55. is_possible = false;
  56. } else {
  57. found_dog = true;
  58. if (found_dot) {
  59. if (last_s >= 2) {
  60. ans.push_back(last_s - 1);
  61. last_f = last_s - 1;
  62. ++last_s;
  63. ++last_t;
  64. } else {
  65. ans.push_back(last_s);
  66. last_f = last_s;
  67. ++last_s;
  68. ++last_t;
  69. }
  70. } else {
  71. if (last_t >= 2) {
  72. ans.push_back(1);
  73. last_f = 1;
  74. ++last_t;
  75. } else {
  76. ans.push_back(0);
  77. last_f = 0;
  78. ++last_t;
  79. }
  80. }
  81. }
  82. } else if (symb[i] == '.') {
  83. if (found_dot) {
  84. is_possible = false;
  85. } else {
  86. found_dot = true;
  87. if (found_dog) {
  88. if (last_t - last_s >= 3) {
  89. ans.push_back(last_f + 2);
  90. last_s = last_f + 2;
  91. ++last_t;
  92. } else {
  93. ans.push_back(last_t);
  94. last_s = last_t;
  95. ++last_t;
  96. }
  97. } else {
  98. if (last_t >= 2) {
  99. ans.push_back(last_t - 1);
  100. last_s = last_t - 1;
  101. ++last_t;
  102. } else {
  103. ans.push_back(last_t);
  104. last_s = last_t;
  105. ++last_t;
  106. }
  107. }
  108. }
  109. } else {
  110. if (last_f == 0) {
  111. ans.push_back(0);
  112. ++last_f;
  113. ++last_s;
  114. ++last_t;
  115. } else if (last_s == last_f + 1) {
  116. ans.push_back(last_s);
  117. ++last_s;
  118. ++last_t;
  119. } else if (last_t == last_s + 1) {
  120. ans.push_back(last_s);
  121. ++last_t;
  122. }
  123. }
  124.  
  125. size_of_first_part = last_f;
  126. size_of_second_part = last_s - last_f - 1;
  127. size_of_third_part = last_t - last_s - 1;
  128.  
  129. if (is_possible && found_dog && found_dot &&
  130. size_of_first_part != 0 && size_of_second_part != 0 && size_of_third_part != 0) {
  131. for (int j = 0; j < ans.size(); ++j)
  132. cout << ans[j] << ' ';
  133. break;
  134. }
  135. }
  136.  
  137. if (!is_possible)
  138. cout << "Impossible";
  139. }
  140.  
  141. return 0;
  142. }
  143.  
Advertisement
Add Comment
Please, Sign In to add comment