SHARE
TWEET

Untitled

a guest Jul 23rd, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. typedef long long ll;
  5.  
  6. int cnt[3];
  7. string t[3];
  8. int strt[3];
  9.  
  10. int main(){
  11.  
  12.     string s;
  13.     cin >> s;
  14.     int slen = s.size();
  15.     int tlen = slen / 2;
  16.     for(int i=0; i<3; i++) strt[i] = slen;
  17.  
  18.     for(char c : s){
  19.         cnt[c-'a']++;
  20.     }
  21.  
  22.     for(int i=0; i<slen; i++){
  23.         if(strt[s[i]-'a'] == slen) strt[s[i]-'a'] = i;
  24.     }
  25.  
  26.     for(char c1='a'; c1<='c'; c1++){
  27.         for(char c2='a'; c2<='c'; c2++){
  28.             if(c1 == c2) continue;
  29.             if(strt[c1-'a'] < strt[c2-'a'] and 2*min(cnt[c1-'a'], cnt[c2-'a']) >= tlen){
  30.                 for(int i=0; i<min(cnt[c1-'a'], cnt[c2-'a']); i++) cout << c1 << c2;
  31.                 return 0;
  32.             }
  33.  
  34.         }
  35.  
  36.     }
  37.  
  38.     cout << "IMPOSSIBLE";
  39.  
  40.  
  41.  
  42.  
  43. }
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