问题描述
【问题描述】
对于一个采用字符数组存放的字符串str,设计一个递归算法判断str是否为回文串。回文串是一个正读和反读都一样的字符串,比如level或者noon等就是回文串。
【输入形式】
一个字符串(不包含空格)。
【输出形式】
若该字符串时回文串,则输出Yes,否则输出No
【样例输入1】
level
【样例输出1】
Yes
【样例输入2】
noon
【样例输出2】
Yes
【样例输入3】
good
【样例输出3】
No
C++代码
#include<iostream>
#include<string>
using namespace std;
bool judge(string z);
int main(){
string string;
cin>>string;
if (judge(string)) cout << "Yes" << endl;
else cout << "No" << endl;
}
bool judge(string z){
int n;
n=z.length();
for(int i=0,j=n-1;i<j;i++,j--){
if(z[i]==z[j]){
continue;
}else{
return false;
}
}
return true;
}