Just check the neighbour of every element's left & right neighbour excluding first & last because they has only one neighbour.
So for first check the right neighbour & last check the left neighbour.
///Bismillahir Rahmanir Rahim
///Author: Tanvir Ahmmad
///CSE,Islamic University,Bangladesh
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<vector>
#include<iterator>
#include <functional> ///sort(arr,arr+n,greater<int>()) for decrement of array
/*every external angle sum=360 degree
angle find using polygon hand(n) ((n-2)*180)/n*/
///Floor[Log(b) N] + 1 = the number of digits when any number is represented in base b
using namespace std;
typedef long long ll;
int main()
{
string str,chk="abc";
cin>>str;
for(ll i=1;i<str.size();i++)
{
if(str[i-1]==str[i])
{
if(str[i-1]!='a' && str[i+1]!='a') str[i]=chk[0];
else if(str[i-1]!='b' && str[i+1]!='b') str[i]=chk[1];
else str[i]=chk[2];
}
}
cout<<str<<endl;
return 0;
}
///Alhamdulillah
Problem Link:https:https://codeforces.com/problemset/problem/665/C
Comments
Post a Comment