您的位置:首页 > 其它

回文字符串的测试

2011-09-08 10:37 211 查看
 
#include <iostream>
using namespace std;

void test_int_circle(const int a)
{
int num = a;
int b[10];
int i = 0;
int begin, end;
int temp;
while (num)
{
temp = num % 10;
b[i] = temp;
i++;
num = num / 10;
}
begin = 0;
end = i - 1;
while(begin < end)
{
if (b[begin] == b[end])
{
begin++;
end--;
}
else
{
break;
}
}
if (begin < end)
{
printf("false\n");
}
else
{
printf("true\n");
}
}

void test_char_circle(const char a[], const int length)
{
int begin = 0, end = length -1;
while(a[begin] != NULL && begin < end)
{
if (a[begin] == a[end])
{
begin++;
end--;
}
else
{
break;
}
}
if (begin < end)
{
cout<<"false"<<endl;
}
else
{
cout<<"true"<<endl;
}
}
int main()
{
/*int a;
cout<<"please input the number of you:"<<endl;
cin>>a;
test_circle(a);
/*char a[]={"aaaaaaa"};
cout<<"please input 3 char:"<<endl;
char a[4];
scanf("%s",a);
test_char_circle(a,sizeof(a)-1);
printf("%s\n",a);

return 0;
}


直接上代码 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: