Advertisement
rengetsu

Baltic_ACM_ICPC_A

Oct 12th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. // Baltic ACM ICPC A
  2. #include <iostream>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n, ac1=0, bc1=0, ac2=0, bc2=0;
  7.     char c[1001];
  8.     cin >> n;
  9.     if(n%2!=0)
  10.     {
  11.         cout << "Impossible" << endl;
  12.     }
  13.     else
  14.     {
  15.         for(int i=0;i<n/2;i++)
  16.         {
  17.             cin >> c[i];
  18.             if(c[i]=='a'){ac1+=1;}
  19.             else if(c[i]=='b'){bc1+=1;}
  20.         }
  21.         for(int j=n/2;j<n;j++)
  22.         {
  23.             cin >> c[j];
  24.             if(c[j]=='a'){ac2+=1;}
  25.             else if(c[j]=='b'){bc2+=1;}
  26.         }
  27.         if((ac1+ac2)%2==0 && (bc1+bc2)%2==0 && ac1==ac2 && bc1==bc2)
  28.         {
  29.             for(int y=0;y<n;y++)
  30.             {
  31.                 cout << c[y];
  32.                 if(y!=n-1 && y!=(n/2)-1){cout << "+";}
  33.                 if(y==(n/2)-1){cout<<"=";}
  34.             }
  35.         }
  36.         else
  37.         {
  38.             cout << "Impossible" << endl;
  39.         }
  40.     }
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement