2 ABC ABBCCC
ABC A2B3C
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); int a[] = new int[10005]; int n = input.nextInt(); input.nextLine(); for (int i = 0; i < n; i++) { int count = 1; String str = input.nextLine(); char c[] = str.toCharArray(); for (int j = 1; j < c.length; j++) { if (c[j] == c[j - 1]) { ++count; } else { if (count == 1) { System.out.print(c[j - 1]); } else { System.out.print(count + "" + c[j - 1]); count = 1; } } if (j == c.length - 1) { if (count == 1) { System.out.print(c[j]); } else { System.out.print(count + "" + c[j]); count = 1; } } } System.out.println(); } } }
HDU-1020-Encoding(Java && 弱水三千)
原文地址:http://blog.csdn.net/qq_16542775/article/details/45771525