给你一个由大写字母组成的字符串,你可以用如下规则对其进行编码: 1、 包含K个相同字母的连续字符串可以用KX表示,其中X是相同的字母 2、 如果K为1,不输出K
package test; import java.util.*; public class test { public static void main(String[] args) { int[] num; String str1,str2; Scanner input=new Scanner(System.in); str1=input.nextLine(); str2=input.nextLine(); num=new int[str1.length()]; for(int i=0;i<str1.length();i++){ for(int j=0;j<str2.length();j++){ if(str2.charAt(j)==str1.charAt(i)) num[i]++; }} for(int i=0;i<str1.length();i++){ if(num[i]==1) System.out.print(str1.charAt(i)); else System.out.print(num[i]+""+str1.charAt(i)); } } }