Created
March 12, 2018 03:05
-
-
Save Zyro9922/ad55ab23d2de422ad17a9baa3a510249 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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