daily pastebin goal
49%
SHARE
TWEET

Untitled

a guest Oct 21st, 2018 65 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     string s;
  9.     cin >> s;
  10.     char last = ' ';
  11.     int poz_1 = -1;
  12.     int min_len = 1000003;
  13.     for (int i = 0; i < s.length(); i++) {
  14.         if(last == ' ' && (s[i] == 'A' || s[i] == 'B')){
  15.             last = s[i];
  16.             poz_1 = i;
  17.         }
  18.         else{
  19.             if((s[i] == 'B' && last == 'A' )|| (s[i] == 'A' && last == 'B')){
  20.                 min_len = min(min_len, i - poz_1 - 1);
  21.                 poz_1 = i;
  22.                 last = s[i];
  23.             }
  24.             else if(s[i] == last){
  25.                 poz_1 = i;
  26.             }
  27.         }
  28.     }
  29.     if(min_len == 1000003)
  30.         cout << 1;
  31.     else
  32.         cout << s.length() - min_len;
  33.     return 0;
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top