第1个回答 2010-10-13
#include <stdio.h>
#include<string>
int main( void )
{
char s[81];
scanf("%s",s);
printf("%s\n",strrev(s));
return 0;
}
//vs2005调试通过
第2个回答 2010-10-13
string方法 -- C++
#include<iostream>
#include<string>
using namespace std;
int main()
{
string x;
int L;
cout<<"Please enter a string:"<<endl;
cin >> x;
L = x.length();
while ( L > 0){
L--;
cout << x.at(L);
}
return 0;
}
第3个回答 2010-10-13
string reverse(const string& s)
{
int start=0;
int end=s.length();
string temp(s);
while(start< end){
swap(temp[start],temp[end]);
start++;
end--;
}
return temp;
}
void swap(char& v1,char& v2)
{
char temp=v1;
v1=v2;
v2=temp;
}