Skip to content

Instantly share code, notes, and snippets.

@Zyro9922
Created March 12, 2018 03:05
Show Gist options
  • Save Zyro9922/ad55ab23d2de422ad17a9baa3a510249 to your computer and use it in GitHub Desktop.
Save Zyro9922/ad55ab23d2de422ad17a9baa3a510249 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string.h>
using namespace std;
int numPal(char s[1000])
{
int ans = 0;
//odd loop
for(int i = 0 ; i < strlen(s) ; i++)
for(int j = 0 ; (i+j) < strlen(s) && (i-j) >= 0 ; j++)
{
if(s[i+j] != s[i-j])
break;
else ans++;
}
//even loop
for(int i = 0 ; i < strlen(s) ; i++)
for(int j = 0 ; (i+j+1) < strlen(s) && (i-j) > 0 ; j++)
{
if(s[i+j+1] != s[i-j])
break;
else ans++;
}
return ans;
}
int main()
{
char s[1000];
cin>>s;
cout<<endl<<numPal(s);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment