题解 | 游游的字母翻倍 ,问:怎么写更优雅

游游的字母翻倍

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

#include <bits/stdc++.h>
using namespace std;

int main() {
    string s;
    int n,q,l,r;
    cin>>n>>q;
    cin>>s;

    while(q--){
        cin>>l>>r;
        for(int i=r-1;i>=l-1;i--){
            string c = "";
            c.push_back(s[i]);
            s.insert(i,c);
        }
    }
    cout<<s<<"\n";
}
// 64 位输出请用 printf("%lld")

原来还有这种函数

s.insert(i,1,s[i]);

全部评论

相关推荐

12-08 15:35
浙江大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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