Odd Palindrome Gym - 101652N

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<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
bool judge(string s)
{
	for(int i=0,j=s.size()-1;i<=j;i++,j--)
	{
		if(s[i]!=s[j])
			return false;
	}
	return true;
}
int main()
{
	string str;
	while(cin>>str)
	{
		bool flag=true;
		for(int i=2;i<=str.size();i+=2)
		{
			for(int j=0;j<=str.size()-i;j++)	
			{
				string temp=str.substr(j,i);
				if(judge(temp))
				{
					flag=false;
					break;
				}			
			}
		}
		if(flag)cout<<"Odd."<<endl;
		else cout<<"Or not."<<endl;

	}
	return 0;
}

Odd.

猜你喜欢

转载自blog.csdn.net/weixin_40543696/article/details/89047202