题解 | #字符串反转#

字符串反转

https://www.nowcoder.com/practice/e45e078701ab4e4cb49393ae30f1bb04

#include<iostream>
#include<string>
using namespace std;

void StrReverse(string &str)
{
    int start=0;
    int end=str.size()-1;
    while(start<end)
    {
        int tmp=str[start];
        str[start]=str[end];
        str[end]=tmp;
        start++;
        end--;
    }
}


int main()
{
    string str;
    while(getline(cin,str))
    {
        StrReverse(str);
        cout<<str<<endl;
    }
    return 0;
}

全部评论

相关推荐

11-04 19:05
已编辑
东莞城市学院 单片机
不知道怎么取名字_:你这个要实习两年?哪有这么久的,感觉就是即使你毕业了,但还按实习的话,是不是不用给你缴社保公积金啥的
点赞 评论 收藏
分享
11-06 16:50
门头沟学院 Java
用微笑面对困难:word打字比赛二等奖的我,也要来凑合凑合
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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