public class HeiMa {
public static void main(String[] args) {
test_1();
}
public static void test_1() {
BufferedReader br = null;
BufferedWriter bw = null;
try {
br = new BufferedReader(new InputStreamReader(System.in));
bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(
"e:" + File.separator + "test.txt",true)));
String line = null;
while((line = br.readLine()) != null){
bw.write(line);
bw.newLine();
bw.flush();
countNumber(line);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
if(br == null)
try {
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void countNumber(String line) {
HashMap<Character,Integer> hm = new HashMap<>();
char[] chs = line.toCharArray();
for(int x = 0;;x++){
if(x == chs.length)
break;
Integer value = hm.get(chs[x]);
int count = 1;
if(value != null)
count = value + 1;
hm.put(chs[x], count);
printMap(hm);
}
}
public static void printMap(HashMap<Character, Integer> hm) {
StringBuilder sb = new StringBuilder();
Set<Map.Entry<Character, Integer>> set = hm.entrySet();
for(Iterator<Map.Entry<Character, Integer>> it = set.iterator();it.hasNext();){
Map.Entry<Character, Integer> kv = it.next();
Character key = kv.getKey();
Integer value = kv.getValue();
sb.append(key+"("+value+")");
}
System.out.println(sb.toString());
}
} |