PLNDROME - Palindrome Or Not - SPOJ Solution C++

  Problem Link : PLNDROME  


👉 Hint : edit please

 


✅ C++ Solution :

 
#include<bits/stdc++.h>
using namespace std;
unordered_set<int> us;
int main()
{
	int t;
	cin>>t;
	for(int r=1;r<=t;r++)
	{
		us.clear();
		int n,cnt=0;
		cin>>n;
		string s;
		cin>>s;
		int l =s.length();
		for(int i=0;i<=(l-1)/2;i++)
		{
			if(s[i]==s[l-1-i])
			{
				cnt++;
				us.insert(i);
			}
		}
		int m;
		cin>>m;
		int x,p;
		char c;
		cout<<"Case "<<r<<":\n";
		while(m--)
		{
			cin>>x>>c;
			s[x-1]=c;
			p=min(x-1,l-x);
			
			
			if(us.find(p)!=us.end())
			{
				cnt--;
				us.erase(p);
			}

			if(s[x-1]==s[l-x])
			{
				cnt++;
				us.insert(p);
			}
			if(cnt==ceil(double(l)/2))
				cout<<"YES\n";
			else
				cout<<"NO\n";
		}
	}
}

 

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!!