对于检查一个字符串是不是回文序列,我们有很多的方法:
有使用递归的也有不使用递归的,在这里我就不再赘述了,下面是我用string字符串的一个解决方法:
-
-
-
-
-
- #include <iostream>
- #include <string>
- using namespace std;
-
- int main( )
- {
- string str;
- cout<<"please input your number/n";
- cin>>str;
- cout<<"you have input:"<<str<<endl;
-
- string rever_str;
- int i=str.length( )-1;
- for( ; i>-1 ;--i)
- {
- rever_str+=str[ i ];
- }
- cout<<"the reverse string:"<<rever_str<<endl;
- if( str==rever_str )
- cout<<"yes/n";
- else
- cout<<"no/n";
-
- return 0;
- }