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

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

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

#include <algorithm>
#include <any>
#include<bits/stdc++.h>
using namespace std;
// write your code here......
void reverse(string &s);

int main(){
    string s;
    getline(cin,s);
    // write your code here......
    
    reverse(s);

    cout<<s;
    return 0;
}

void reverse(string &s)
{
    for (int i = 0; i < s.size() / 2; ++i)
        swap(s[i], s[s.size() - 1 -i]);
}

void swap(int &m, int &n)
{
    int temp = m;
    m = n;
    n = temp;
}

按照题目使用引用进行转换

C++题解 文章被收录于专栏

记录在牛客网用C++刷题的题解思路

全部评论

相关推荐

03-05 17:03
已编辑
浙江工商大学 C++
陈好好wy:整体看下来有点空空的感觉,可以把每一段项目经历都再完善一下,然后用小标题的形式写个两到三条,目前看有点太简单了,不太能看出具体在这个项目里做了什么工作。还是要尽量把自己做的工作以量化的形式体现在简历上呢。
双非本科求职如何逆袭
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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