Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.84 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<string>
  4. using namespace std;
  5.  
  6. int main() {
  7.     ios_base::sync_with_stdio(false);
  8.     cin.tie(nullptr);
  9.  
  10.     string s1, s2;
  11.     cin >> s1 >> s2;
  12.     char last_symbol = ' ';
  13.     int first_index = -1;
  14.     int last_index = -1;
  15.     int flag = 0;
  16.     int i = 0;
  17.     int j = 0;
  18.  
  19.     while ((i < s1.length()) && (j < s2.length())) {
  20.         if ((flag == 0) && (s1[i] != s2[j]) && (first_index == -1)) {
  21.             cout << 0 << endl;
  22.             return 0;
  23.         }
  24.         if ((s1[i] == s2[j]) && (flag == 0)) {
  25.             if (s1[i] != last_symbol) {
  26.                 last_symbol = s1[i];
  27.                 first_index = i;
  28.                 last_index = i;
  29.                 i++;
  30.                 j++;
  31.             }
  32.             else {
  33.                 last_index = i;
  34.                 i++;
  35.                 j++;
  36.             }
  37.         }
  38.         if ((s1[i] != s2[j]) && (flag == 0)) {
  39.             flag = 1;
  40.             if (s1[i] != last_symbol) {
  41.                 first_index = i;
  42.                 last_index = i;
  43.             }
  44.             else {
  45.                 last_index = i;
  46.             }
  47.             i++;
  48.             continue;
  49.         }
  50.         if (flag == 1) {
  51.             if (s1[i] ==  s2[j]) {
  52.                 i++;
  53.                 j++;
  54.                 continue;
  55.             }
  56.             else {
  57.                 cout << 0 << endl;
  58.                 return 0;
  59.             }
  60.         }  
  61.     }
  62.  
  63.     if (i == j) {
  64.  
  65.         cout << last_index - first_index + 2 << endl;
  66.         for (int k = first_index; k < last_index + 2; k++){
  67.             cout << k + 1 << " ";
  68.         }
  69.     }
  70.     else {
  71.         cout << last_index - first_index + 1 << endl;
  72.         for (int k = first_index; k < last_index + 1; k++){
  73.             cout << k + 1 << " ";
  74.         }
  75.     }
  76.    
  77.  
  78.  
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement