【leetcode 23】54. 替换数字(第八期模拟笔试)

java 复制代码
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        String s=sc.next();
        int len=s.length();
        for(int i=0;i<s.length();i++){
            if(s.charAt(i)>='0'&&s.charAt(i)<='9'){
                len+=5;
            }
        }
        char[] rest=new char[len];
        for(int i=0;i<s.length();i++){
            rest[i]=s.charAt(i);
        }
        for(int i=s.length()-1,j=len-1;i>=0;i--){
            if(rest[i]>='0'&&rest[i]<='9'){
                rest[j--]='r';
                rest[j--]='e';
                rest[j--]='b';
                rest[j--]='m';
                rest[j--]='u';
                rest[j--]='n';

            }else{
                rest[j--]=rest[i];
            }
        }
        System.out.println(rest);
    }
}
相关推荐
骄马之死1 小时前
SpringMVC + SpringBoot 核心知识点总结
java·spring boot·后端
Frostnova丶2 小时前
【算法笔记】数学知识
笔记·算法
吴可可1232 小时前
AutoCAD 2016与2014二次开发关键差异
算法
郑洁文3 小时前
基于Spring Boot的流浪动物救助网站
java·spring boot·后端·毕设·流浪动物救助
雨白3 小时前
哈希:以时间换空间的算法实战
算法
螺丝钉code4 小时前
JAVA项目 Claude code CLAUDE.md 到底应该怎么写
java·人工智能·claude code
摇滚侠5 小时前
Maven 入门+高深 单一架构案例 54-59
java·架构·maven·intellij-idea
VidDown5 小时前
Webhook 调试器:让第三方回调“原形毕露”
java·开发语言·javascript·编辑器·postman
San813_LDD5 小时前
[数据结构]LeetCode学习
数据结构·算法·图论