题解 | #翻转字符串(2)#

翻转字符串(2)

http://www.nowcoder.com/practice/79c562297c0e4ff0952ef39ecde1bd6b

//翻手掌算法
//该算法的思想为先把左边区域逆序再把右边区域逆序最后整体逆序即可
#include<bits/stdc++.h>
using namespace std;
int main(){
    int size;
    cin>>size;
    string str;
    cin>>str;
    int start=0,end=size-1;
    //逆序左半区域
    while(start<=end){
        char temp=str[start];
        str[start]=str[end];
        str[end]=temp;
        start++;
        end--;
    }
    //逆序右半区区域
    start=size,end=str.size()-1;
    while(start<=end){
        char temp=str[start];
        str[start]=str[end];
        str[end]=temp;
        start++;
        end--;
    }
    //整体逆序
    start=0,end=str.size()-1;
    while(start<=end){
        char temp=str[start];
        str[start]=str[end];
        str[end]=temp;
        start++;
        end--;
    }
    cout<<str<<endl;
    return 0;
}
全部评论

相关推荐

给我发了笔试链接,想着等晚上回去做,结果还没做流程就终止了
伟大的小黄鸭在学习:我猜就是笔试几乎没用,就是用来给用人部门拖时间复筛简历的,可能用人部门筛到你简历觉得不合适就提前挂了
投递小鹏汽车等公司10个岗位
点赞 评论 收藏
分享
码砖:求职岗位要突出,一眼就能看到,教育背景放到最后,学校经历没那么重要,项目要重点突出
点赞 评论 收藏
分享
下北澤大天使:你是我见过最美的牛客女孩😍
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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