回文数_但程序中使用了strcpy和strlen

来源:互联网 发布:软件测试思路 编辑:程序博客网 时间:2024/03/28 18:57
#include <iostream>#include <stdlib.h>#include <assert.h>#include <stdio.h>using namespace std;bool isPalindrome(char *input){assert(input != NULL);//定义缓存char s[100];strcpy(s,input);//计算输入字符串的长度int length = strlen(input);//int begin = 0;int end = length - 1;//while(begin < end){if(s[begin] == s[end]){begin++;end--;}else{break;}}//跳出上循环后,如果是正常结束则为回文数if(begin < end){return false;}else{return true;}}void main(){char *str = "abccba";//char *str;//char *str = "";//这里我输入了几个空格和tab 但是还是对称的。if(isPalindrome(str)){cout << "Yes"<<endl;}else{cout << "No" <<endl; }}