525B. Pasha and String - Codeforces Solution C++

  Problem Link : 525B. Pasha and String 


✅ C++ Solution :

 
#include<bits/stdc++.h>
using namespace std;

int main()
{
	string s;
	cin>>s;
	int l=s.length();
	int m,val;
	cin>>m;
	int cum[l/2];
	memset(cum,0,sizeof(cum));
	for(int i=0;i<m;i++)
	{
		cin>>val;
		cum[val-1]++;
	}
    
    for(int i=1;i<l/2;i++)
        cum[i]+=cum[i-1];
        
    for(int i=0;i<l/2;i++)
    {
        if(cum[i]%2)
        {
            char t=s[i];
            s[i]=s[l-i-1];
            s[l-i-1]=t;
        }
    }
    
    cout<<s;



}

 

Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook. 

😇Happy Learning!!