程序代码:
import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()) { String s = in.next(); char type = s.charAt(0); String str = new Scanner(System.in).nextLine(); char[] c = str.toCharArray(); if (type == 'C') { System.out.println("cccccc"); int len = str.length(); int cnt = 1; for (int i = 0; i < len - 1; i++) { if (c[i] == c[i + 1]) { cnt++; } else if(c[i] != c[i + 1]){ if (cnt > 1) { System.out.printf("%d", cnt); } System.out.printf("%c", c[i]); cnt = 1; } } } else { System.out.println("dddddd"); int len = str.length(); int cnt = 0; for (int i = 0; i < len; i++) { if (c[i] <= '9' && c[i] >= '0') { cnt *= 10; cnt += c[i] - '0'; } else { if (cnt == 0) { System.out.printf("%c", c[i]); } else for (int j = 0; j < cnt; j++) { System.out.printf("%c", c[i]); } cnt = 0; } } } } in.close(); } }你再参考一下我的,把细节处理好,就可以了
假如人生没有梦想,和咸鱼有什么区别!