C++编程 判断回文串,求大神帮助

2025-04-18 12:47:19
推荐回答(1个)
回答1:

代码资料:

//#include "stdafx.h"//If the vc++6.0, with this line.

#include

#include

using namespace std;

int main(int argc,char *argv[]){

string s;

int i,j,k;

cout << "k(int k>0)...\n";

if(!(cin >> k) || k<1){

cout << "Input error, exit...\n";

return 0;

}

while(k--){

cout << "Please enter a string(No ' ')...\n";

cin >> s;

if(s.length()>50)

s.assign(s,0,49);

for(j=s.length()-1,i=0;i

if(s[i]-s[j])

break;

cout << (i>=j ? 'Y' : 'N') << endl;

}

return 0;

}