Advertisement
rahat62

A - Prefixes

Sep 25th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int t,cnt=0;
  6.     cin>>t;
  7.     char ch[t];
  8.  
  9.     for(int i=0;i<t;i++)
  10.     {
  11.         cin>>ch[i];
  12.     }
  13.  
  14.     for(int i=0;i<t;i=i+2)
  15.     {
  16.         if(ch[i]=='a' && ch[i+1]!='b') {cnt ++;
  17.             ch[i+1] = 'b';
  18.         }
  19.  
  20.         if(ch[i]=='b' && ch[i+1]!='a') {cnt ++;
  21.  
  22.             ch[i+1] = 'a';
  23.         }
  24.     }
  25.     cout<<cnt<<endl;
  26.     for(int i=0;i<t;i++)
  27.     {
  28.         cout<<ch[i];
  29.     }
  30.     cout<<endl;
  31.  
  32.  
  33.  
  34.  
  35.  
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement