百词斩字符串

public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        byte[] line = scanner.nextLine().getBytes();
//        byte[] line1 = "aaasddasuuuuuuujjjjjjssssss".getBytes();
//        byte[] line1 = "aaasdd".getBytes();
        test2(line);

    }
    public static void test2(byte[] line){
        int count = 1 ;
        byte tmp = 0 ;
        String res = "";
        for (int i = 0; i < line.length ; i++) {
            if( tmp == 0){
                tmp = line[ i ];
                res = res + new String(new byte[]{line[ i ]});
            }
            if( (i < line.length-1 && tmp != line[ i + 1 ] ) || i == line.length -1 ){
                tmp = 0 ;
            }else{
                count ++ ;
            }

            if( count > 1 && tmp == 0 ){
                res = res + count;
                count = 1 ;
            }
        }

        System.out.println( res );
    }

#笔试题目#
全部评论

相关推荐

认真搞学习:这么良心的老板真少见
点赞 评论 收藏
分享
06-23 11:28
门头沟学院 Java
牛客919661971号:也有可能是点拒绝的时候自动弹的话术
点赞 评论 收藏
分享
评论
2
1
分享

创作者周榜

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