【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 分钟前
Spring Cloud Gateway 核心篇:深入解析过滤器(Filter)机制与实战
java·服务器·网络·后端·微服务·gateway
adore.9682 分钟前
2.24 oj95 96 97
开发语言·c++·算法
笨蛋不要掉眼泪4 分钟前
Spring Cloud Gateway 扩展:全局跨域配置
java·分布式·微服务·架构·gateway
白中白121384 分钟前
算法题-16
算法
梦帮科技5 分钟前
【DREAMVFIA开源】量子互联网协议:节点通信与路由算法
人工智能·神经网络·算法·生成对抗网络·开源·量子计算
菜鸡儿齐10 分钟前
leetcode-搜索插入位置
数据结构·算法·leetcode
52Hz11811 分钟前
力扣394.字符串解码、739.每日温度、84.柱状图中最大的矩形
python·算法·leetcode
java1234_小锋11 分钟前
Java高频面试题:说说Redis的内存淘汰策略?
java·开发语言·redis
Yzzz-F15 分钟前
牛客寒假算法训练营4
算法
编程小白_澄映16 分钟前
《机器学习》——KNN算法
人工智能·算法·机器学习