参考代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String s = scanner.nextLine(); System.out.print(p(s)); } public static String p(String s) { String res = ""; int cnt = 1; for(int i = 1; i < s.length(); i++) { if(s.charAt(i) == s.charAt(i - 1)) cnt++; else { res = res + cnt + s.charAt(i - 1); cnt = 1; } if(i == s.length() - 1) res = res + cnt + s.charAt(i); } return res; } }
0.0分
5 人评分
C语言程序设计教程(第三版)课后习题8.9 (C语言代码)浏览:570 |
简单的a+b (C语言代码)浏览:548 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:482 |
P1002 (C语言代码)浏览:980 |
C语言程序设计教程(第三版)课后习题8.1 (C语言代码)浏览:1258 |
C语言程序设计教程(第三版)课后习题6.6 (C++代码)浏览:633 |
幸运数 (C++代码)浏览:1265 |
2004年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:324 |
C语言程序设计教程(第三版)课后习题12.3 (C语言代码)浏览:548 |
明明的随机数 (C语言代码)浏览:953 |