353 Pesky Palindromes

 

Problem Link

#Source Code

#include<bits/stdc++.h>
#define pb push_back
#define sf(x) scanf(“%d”,&x)
#define MN 1234567
#define max 10000
#define all(water) (water.begin(),water.end());
#define fr(i,a,b) for(i=a;i<b;i++)
using namespace std;
#define cln(a) memset(a,0,sizeof(a))
#define ll long long

bool ispalin(const string &s)
{
string rev(s);
reverse(rev.begin(), rev.end());
return s == rev?1:0;
}
int main()
{
string str;
while(cin>>str){
map<string,int>mem;
ll co=0,i,j,l=str.size();
for(size_t i=0;i<l;i++)
{
for(size_t j=i;j<l;j++)
{
string sub=str.substr(i,j-i+1);
if(!mem.count(sub) &&ispalin(sub))
{
++co;
++mem[sub];
}

}
}
cout << “The string ‘”
<< str
<< “‘ contains ”
<< co
<< ” palindromes.”
<< endl;
}
return 0;
}

Advertisements

About waprogramming

I am in CSE,from CUET
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s