题解 | 字符串操作

字符串操作

https://www.nowcoder.com/practice/06a5336b64e3481fbbcc1f7d5cba548d

import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int len = in.nextInt(),times = in.nextInt();
        String s = in.next();
        StringBuilder str = new StringBuilder(s);
        while(times-->0){
            int i = in.nextInt(),n = in.nextInt();
            char c1 = in.next().charAt(0),c2 = in.next().charAt(0);
            for(;i<=n;i++){
                if(str.charAt(i-1)==c1){
                    str.setCharAt(i-1,c2);
                }
            }
        }
        System.out.println(str);
    }
}

全部评论

相关推荐

迷茫的大四🐶:28?别太离谱,研究生出来也得25至少了
牛客吐槽大会
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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