Problem A — limit 1 second Odd Palindrome We say that a string is odd if and only if all palindromic substrings of the string have odd length. Given a string s, determine if it is odd or not. A substring of a string s is a nonempty sequence of consecutive characters from s. A palindromic substring is a substring that reads the same forwards and backwards. Input The input consists of a single line containing the string s (1 ≤ |s| ≤ 100). It is guaranteed that s consists of lowercase ASCII letters (‘a’–‘z’) only. Output If s is odd, then print “Odd.” on a single line (without quotation marks). Otherwise, print “Or not.” on a single line (without quotation marks). Sample Input and Output
amanaplanacanalpanama Odd. madamimadam Odd. annamyfriend Or not. nopalindromes Odd.
题意: 所有的回文子串都是奇数。
#include <cstdio> #include <algorithm> #include <cstring> using namespace std; char s[1005]; int main() { scanf("%s",s + 1); int n = (int)strlen(s + 1); int flag = 0; for(int i = 2;i <= n;i++) { if(s[i] == s[i - 1]) { flag = 1; break; } } if(flag) printf("Or not."); else printf("Odd."); return 0; }