Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- int main()
- {
- string raw;
- getline(cin, raw);
- string symb;
- getline(cin, symb);
- bool found_dog = false;
- bool found_dot = false;
- int last_f = 0;
- int last_s = 0;
- int last_t = raw.size();
- int cnt = 0;
- bool is_possible = true;
- for (int i = 0; i < raw.size(); ++i) {
- if (raw[i] == '@') {
- if (found_dot)
- is_possible = false;
- else {
- last_f = cnt;
- found_dog = true;
- }
- } else if (raw[i] == '.') {
- last_s = cnt;
- found_dot = true;
- }
- ++cnt;
- }
- int size_of_first_part = last_f;
- int size_of_second_part = last_s - last_f - 1;
- int size_of_third_part = last_t - last_s - 1;
- if (!is_possible) {
- cout << "Impossible";
- } else if (found_dog && found_dot &&
- size_of_first_part != 0 && size_of_second_part != 0 && size_of_third_part != 0) {
- cout << "Done";
- } else {
- vector<int> ans;
- for (int i = symb.size() - 1; i >= 0 && is_possible; --i) {
- if (symb[i] == '@') {
- if (found_dog) {
- is_possible = false;
- } else {
- found_dog = true;
- if (found_dot) {
- if (last_s >= 2) {
- ans.push_back(last_s - 1);
- last_f = last_s - 1;
- ++last_s;
- ++last_t;
- } else {
- ans.push_back(last_s);
- last_f = last_s;
- ++last_s;
- ++last_t;
- }
- } else {
- if (last_t >= 2) {
- ans.push_back(1);
- last_f = 1;
- ++last_t;
- } else {
- ans.push_back(0);
- last_f = 0;
- ++last_t;
- }
- }
- }
- } else if (symb[i] == '.') {
- if (found_dot) {
- is_possible = false;
- } else {
- found_dot = true;
- if (found_dog) {
- if (last_t - last_s >= 3) {
- ans.push_back(last_f + 2);
- last_s = last_f + 2;
- ++last_t;
- } else {
- ans.push_back(last_t);
- last_s = last_t;
- ++last_t;
- }
- } else {
- if (last_t >= 2) {
- ans.push_back(last_t - 1);
- last_s = last_t - 1;
- ++last_t;
- } else {
- ans.push_back(last_t);
- last_s = last_t;
- ++last_t;
- }
- }
- }
- } else {
- if (last_f == 0) {
- ans.push_back(0);
- ++last_f;
- ++last_s;
- ++last_t;
- } else if (last_s == last_f + 1) {
- ans.push_back(last_s);
- ++last_s;
- ++last_t;
- } else if (last_t == last_s + 1) {
- ans.push_back(last_s);
- ++last_t;
- }
- }
- size_of_first_part = last_f;
- size_of_second_part = last_s - last_f - 1;
- size_of_third_part = last_t - last_s - 1;
- if (is_possible && found_dog && found_dot &&
- size_of_first_part != 0 && size_of_second_part != 0 && size_of_third_part != 0) {
- for (int j = 0; j < ans.size(); ++j)
- cout << ans[j] << ' ';
- break;
- }
- }
- if (!is_possible)
- cout << "Impossible";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment