题解 | #查找#

查找

http://www.nowcoder.com/practice/a988eda518f242c29009f8620f654ede

#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
void reverse(string &s, int left, int length){
    int right = left + length - 1;
    for(int i = left,j = right;i < (left+right+1)/2;++i,--j){
        char temp = s[i];
        s[i] = s[j];
        s[j] = temp;
    }
}
void second(string &s, int left, int length, string change){
    string part1 = s.substr(0,left);
    string part2 = s.substr(left+length);
    s = part1 + change + part2;
}
int main(){
    string s;int n;
    cin >> s >> n ;
    while(n--){
        string temp;
        cin >> temp;
        if(temp[0]-'0' == 0)
            reverse(s, temp[1]-'0', temp[2]-'0');
        else
            second(s, temp[1]-'0', temp[2]-'0', temp.substr(3));
        cout << s <<endl;
    }
    return 0;
}
全部评论

相关推荐

06-27 18:53
门头沟学院 Java
这样才知道自己不适合搞代码,考公去咯
只爱喝白开水:我也发现不适合搞代码,打算转非技术方向了
点赞 评论 收藏
分享
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 18:22
投了几百份简历,专业和方向完全对口,都已读不回。尝试改了一下学校,果然有奇效。
steelhead:这不是很正常嘛,BOSS好的是即便是你学院本可能都会和聊几句,牛客上学院本机会很少了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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