// demo.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include<Windows.h>
//#include <cstdio>
using namespace std;
class Box
{
public:
void fun()
{
len = 0;
char s[100], *p = s;
gets_s(s);
//puts(s);
while (*(p + len) != '\0')
{
//cout << *(p + len) << endl;
len++;
//if (*(p + len) == '\0') { break; }
}
y = len - 1;
x = 0;
i = 0;
while (*(p+x)==s[y]&&i<(len/2))
{
x++;
y--;
i++;
}
if (i == len / 2) {
cout << "是回文" << endl;
}
else {
cout << "不是回文"<<endl;
}
system("pause");
}
private:
int len, x, y, i;
};
int main()
{
Box b;
b.fun();
return 0;
}
判断回文
最新推荐文章于 2024-04-25 08:31:40 发布