fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Scanner sc = new Scanner(System.in);
  13. String str = sc.next();
  14. LinkedHashMap<Character,Integer> lhm = new LinkedHashMap<Character,Integer>();
  15. int i = 0;
  16. while(i<str.length())
  17. {
  18. Integer count = lhm.get(str.charAt(i));
  19. lhm.put(str.charAt(i),(count==null)?1:count+1);
  20. i++;
  21. }
  22. lhm.forEach((key,val)->{
  23. System.out.print(key+""+val);
  24. });
  25. }
  26. }
Success #stdin #stdout 0.15s 2184192KB
stdin
aaaaaaaaaaaaaaagggxs
stdout
a15g3x1s1