C ++ C ++帮助我

扫码查看
本文介绍了C ++ C ++帮助我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

i try to write   code but  i have a problem for  this code.
i want to write reverse is same ( for example : i will write  "madam" reverse is same "madam".

i want to do  STR.. code

What I have tried:

#include<stdio.h>
#include<string.h>

 	int main()

{
	char string [80];


	printf("enter a string : ");
	gets(string);


	strrev(string);
	printf("reverse: %s ",string);





	return 0;
}

推荐答案

char *rev = strdup(string);
strrev(rev);
int compare = strcmp(rev, str);
if (0 == compare)
    printf("'%s' is a palindrome\n", string);
// ...
free(rev);


#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main ()
{
  string s;

  cout << "enter a string " << endl;
  cin >> s;

  string r = s;
  reverse(r.begin(),r.end());

  if ( r == s)
    cout << "the string is palindrome" << endl;
  else
    cout << "the string is not palindrome" << endl;
}


这篇关于C ++ C ++帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 15:29
查看更多