4.25美团笔试,第二题一直是18,有大佬帮忙看一下为什么吗

4.25美团笔试,第二题一直是18,有大佬帮忙看一下为什么吗
public class Main {
    public static void main(String[] args){
        String str;
        int q;
        Scanner sc = new Scanner(System.in);
        str = sc.nextLine();
        char[] ch = str.toCharArray();
        q = sc.nextInt();
        for (int i = 0; i < q; i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            int k = sc.nextInt();
            for (int j = l-1; j < r; j++){
                int a = ch[j]-k;
                if (a < 97){
                    a += 26;
                }
                ch[j] = (char)a;
            }
        }
        String s = String.valueOf(ch);
        System.out.println(s);
    }
}
#美团#
全部评论
if改成while
2 回复
分享
发布于 2021-04-25 12:18
同学过了几道
点赞 回复
分享
发布于 2021-04-25 12:21
博乐游戏
校招火热招聘中
官网直投
这个是n^2的复杂度能过吗
点赞 回复
分享
发布于 2021-04-25 12:22
k很大,直接mod吧
点赞 回复
分享
发布于 2021-04-25 12:27
我直接逆向还原 过了百分之80多
点赞 回复
分享
发布于 2021-04-25 16:02
现在还可以投递吗?快结束了
点赞 回复
分享
发布于 2021-04-25 16:09
k可能很大,先模26 public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); char[] str = in.nextLine().toCharArray(); int c = in.nextInt(); while(c-->0) { int l = in.nextInt(); int r = in.nextInt(); int k = in.nextInt()%26; for(int i = l-1;i<r;i++) { int tmp = str[i] - 'a&(417)#39;; if(tmp - k < 0) { tmp = tmp - k + 26; }else { tmp = tmp - k; } str[i] = (char)(tmp + 'a&(417)#39;); } } System.out.println(new String(str)); }
点赞 回复
分享
发布于 2021-04-25 23:03

相关推荐

点赞 2 评论
分享
牛客网
牛客企业服务