题解 | #编写函数实现字符串翻转(引用方式)#

编写函数实现字符串翻转(引用方式)

http://www.nowcoder.com/practice/46eb5bd3ebc544fc96d335c8cb7d30f1

#include<bits/stdc++.h>
using namespace std;
// write your code here......
void reverse_string(string & s)
{
    int len=s.length();
    for(int i=0;i<len/2;i++)//对称交换
    {
        char temp=s[len-1-i];
        s[len-1-i]=s[i];
        s[i]=temp;
    }
}
int main(){
    string s;
    getline(cin,s);
    // write your code here......
    reverse_string(s);
    cout<<s;
    return 0;
}
全部评论

相关推荐

双尔:反手回一个很抱歉,经过慎重考虑,您与我的预期暂不匹配,感谢您的投递
点赞 评论 收藏
分享
牛客nb666号:见天才的门槛罢了查看图片
点赞 评论 收藏
分享
评论
6
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务