344. Reverse String
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
不多说,就反转一个字符串。
#include<iostream>
#include<string>
using namespace std;
/***************************************提交部分*************************************/
class Solution
{
public:
string reverseString(string s)
{
char tmp;
for(int i=0;i<s.size()/2;i++)
{
tmp=s[i];
s[i]=s[s.size()-1-i];
s[s.size()-1-i]=tmp;
}
return s;
}
};
/************************************************************************************/
int main()
{
string s,ans;
cin>>s;
Solution S;
ans=S.reverseString(s);
cout<<ans<<endl;
return 0;
}