a022.
迴文
| From: [60.249.76.117] |
發表日期
:
2014-07-13 16:15
#include <cstdlib>
#include <iostream>
#include <cstring>
using namespace std;
void check(char a[1000],int num,int i)
{
if(a[num]==a[num+i])
{
if(num==0)
{
cout<<"yes"<<endl;
}
else
{
num=num-1;
i=i+2;
check(a,num,i);
}
}
else if(a[num]!=a[num+i])
{
cout<<"no"<<endl;
}
}
void check2(char a[1000],int num,int i)
{
if(a[num]==a[num+i])
{
if(num==0)
{
cout<<"yes"<<endl;
}
else
{
num=num-1;
i=i+2;
check2(a,num,i);
}
}
else if(a[num]!=a[num+i])
{
cout<<"no"<<endl;
}
}
int main(int argc, char *argv[])
{
char ch[1000];
int len,num,i;
while(cin>>ch)
{
len=strlen(ch);
if(len%2!=0)
{
i=2;
num=len/2-1;
check2(ch,num,i);
}
else
{
i=1;
num=len/2-1;
check(ch,num,i);
}
}
return EXIT_SUCCESS;
}
還是錯了,WA 求助 測資試過沒問題了