Advertisement
1WaKa_WaKa1

Task_b

Mar 5th, 2022
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4.  
  5.  
  6. using namespace std;
  7. int main() {
  8. //Ввод данных
  9. string input;
  10. cin >> input;
  11.  
  12. //Тело программы
  13. vector<int> temp;
  14. map<int,int> animalMap;
  15. int number = 1;
  16. for (int i = 0; i < input.length(); i++){
  17. if (islower(input[i])){
  18. animalMap.insert(make_pair(i, number));
  19. number+=1;
  20. }
  21. }
  22. for (int i = 0; i < input.length(); i++){
  23. if (!temp.empty()){
  24. if (isupper(input[i])){
  25. if (islower(input[temp.back()]) && input[temp.back()] == tolower(input[i])){
  26. animalMap.insert(make_pair(i,animalMap.find(temp.back())->second));
  27. animalMap.extract(temp.back());
  28. temp.pop_back();
  29. } else temp.push_back(i);
  30. } else {
  31. if (isupper(input[temp.back()]) && input[temp.back()] == toupper(input[i])){
  32. animalMap.insert(make_pair(temp.back(),animalMap.find(i)->second));
  33. animalMap.extract(i);
  34. temp.pop_back();
  35. } else temp.push_back(i);
  36. }
  37. }else {
  38. temp.push_back(i);
  39. }
  40. }
  41.  
  42. //Вывод данных
  43. if (!temp.empty()){
  44. cout << "Impossible" << endl;
  45. } else {
  46. cout << "Possible" << endl;
  47. for (int i = 0; i < input.length(); i++){
  48. int znachenie = animalMap.find(i)->second;
  49. if (znachenie !=0){
  50. cout << znachenie << " ";
  51. }
  52. }
  53. }
  54. return 0;
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement