题解 | #字符串反转#
字符串反转
http://www.nowcoder.com/practice/e45e078701ab4e4cb49393ae30f1bb04
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s1;
    cin>>s1;
    char *l,*r;
    l=&s1[0],r=&s1[s1.size()-1];
    while(l<r)//使用指针实现字符串的就地逆置
    {
        char temp=*l;
        *l=*r;
        *r=temp;
        l++;
        r--;
    }
    cout<<s1<<endl;
    return 0;
} 
查看9道真题和解析
