问题描述
例:输入iteye,输出e2i1t1y1zhongguo --> g2h1n1o2u1z1
解决方案
我有一个高效的package com.algorithm.compress;import java.util.Scanner;public class CountTimeOfChar {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入一串字母:");String input = sc.next();int[] count = new int[26];char[] chars = input.toCharArray();//(字母 & 31 ) 可以算出他是第几个字母for(int i = 0, len = chars.length; i < len; count[(chars[i ++] & 31) - 1] ++);//计算每种字符在输入的字符串中出现的次数for(int j = 0, len = count.length; j < len; j ++) {if(count[j] != 0) {System.out.print((char) ('a' + j));System.out.print(count[j]);}}System.out.println();}}
解决方案二:
你这个是统计字符数量http://download.csdn.net/download/hexiang221/1994808http://www.docin.com/p-492662254.html
解决方案三:
如果这是压缩算法,该如何解压??不能解压还原,还有神马意义呢?
解决方案四:
static class Letter implements Comparable<Letter> {char ch;int count;public Letter(char ch, int count) {super();this.ch = ch;this.count = count;}public void increase() {count++;}public String toString() {return ch + "" + count;}public int compareTo(Letter o) {if (this.count > o.count)return -1;else if (this.count < o.count)return 1;if (this.ch > o.ch)return 1;else if (this.ch < o.ch)return -1;return 0;}}public static String statistic(String s) {HashMap<Character, Integer> count = new HashMap<Character, Integer>();int n = s.length();for (int i = 0; i < n; i++) {Character ch = s.charAt(i);Integer c = count.get(ch);if (c == null) {count.put(ch, 1);} else {count.put(ch, c + 1);}}int m=count.size();Letter[] arr=new Letter[m];int index=0;for(Entry<Character, Integer> e:count.entrySet()){arr[index++]=new Letter(e.getKey(), e.getValue());}Arrays.sort(arr);StringBuilder sb = new StringBuilder(n * 2);for (Letter letter:arr) {sb.append(letter);}return sb.toString();}
解决方案五:
这个只是简单的统计吧
解决方案六:
问非所问,答非所答
解决方案七:
这是字符串压缩吗?明显是字符统计啊