Last active
November 5, 2019 08:34
-
-
Save pinglunliao/76729dc0358d3a1976d6 to your computer and use it in GitHub Desktop.
a022: 迴文 FYI: https://yunlinsong.blogspot.com/2016/02/blog-post_7.html
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> | |
using namespace std; | |
void msg(bool b); | |
bool isPalindrome( const string &s ); | |
int main() | |
{ | |
string str; | |
while(cin >> str) | |
{ | |
msg(isPalindrome(str)); | |
} | |
return 0; | |
} | |
void msg(bool b) | |
{ | |
cout << (b?"yes":"no") << endl; | |
} | |
bool isPalindrome( const string &s ) | |
{ | |
short len = s.length(); | |
for(short i = 0; i < len / 2; i++) | |
{ | |
if( s[i] != s[len - 1 - i] ) | |
return false; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment