参考代码:
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语言训练-计算1~N之间所有奇数之和 (C语言代码)浏览:820 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:325 |
点我有惊喜!你懂得!浏览:1403 |
C语言训练-阿姆斯特朗数 (C语言代码)浏览:855 |
妹子杀手的故事 (C语言代码)浏览:691 |
数对 (C语言代码)浏览:703 |
C语言程序设计教程(第三版)课后习题10.2 (C语言代码)浏览:1466 |
C语言程序设计教程(第三版)课后习题10.3 (C语言代码)浏览:1921 |
杨辉三角 (C语言代码)浏览:484 |
【偶数求和】 (C++代码)浏览:701 |