HDOJ-ACM1020(JAVA)

 

题意:给字母计数,如果是字母后面没有相同的,原样输出,如果有则输出这个字母的个数和字母本身。

import java.util.*;

import java.io.*;

public class Main{

    public static void main(String[] arg){
        Scanner scan = new Scanner(new BufferedInputStream(System.in));
        int n =scan.nextInt();
        while(n--!=0){
            String s = scan.next();
            char[] cs = s.toCharArray();
            int len = cs.length;
            int count = 1;
            int last = len -1;
            String result = "";
            for(int i = 0 ; i != len ; i ++){
                if(i!=last&&cs[i] == cs[i+1]){
                    count++;
                    continue;
                }
                if(count == 1){
                    result = result +  cs[i];
                    continue;
                }
                result = result + count + cs[i];
                count=1;
            }
            System.out.println(result);
        }
        scan.close();

    }

}

 

posted on 2016-06-13 21:25  xiezie  阅读(221)  评论(0编辑  收藏  举报

导航