题解 | #人民币转换#

表示数字

http://www.nowcoder.com/practice/637062df51674de8ba464e792d1a0ac6

import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        while(in.hasNextLine()){
            String str = in.nextLine();
            String res = "";
            int k = 0;
            int m = 0;
            boolean isNum = false;
            while(k < str.length()){
                if(str.charAt(k)>='0'&&str.charAt(k)<='9'){
                    if(!isNum){
                        res += str.substring(m, k);
                        m = k;
                        isNum = true;
                    } else {
                        if(++k == str.length()){
                            res += "*" + str.substring(m, k) + "*";
                        }
                    }
                } else {
                    if(isNum){
                        res += "*" + str.substring(m, k) + "*";
                        m = k;
                        isNum = false;
                    } else {
                        if(++k == str.length()){
                            res += str.substring(m, k);
                        }
                    }
                }
            }
            System.out.println(res);
        }
    }
}
全部评论

相关推荐

06-19 19:06
门头沟学院 Java
码农索隆:别去东软,真学不到东西,真事
点赞 评论 收藏
分享
醉蟀:你不干有的是人干
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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