fork download
  1. import java.util.Scanner;
  2. class Main{
  3. public static void main(String args[]){
  4. Scanner scan = new Scanner(System.in);
  5. String st = scan.next();
  6. char ch;
  7. int st1 = 1;
  8. char[] result = new char[st.length()];
  9. for(int i = st.length()-1; i >= 0; i--) {
  10. result[i] = st.charAt(i);
  11. }
  12. for(int i = 0; i <= st.length()-1; i++) {
  13. for(int j = 0; j < st.length()-1 ; j++) {
  14. if(result[j] > result[j+1]){
  15. ch = result[j];
  16. result[j] = result[j+1];
  17. result[j+1] = ch;
  18. }
  19. }
  20. }
  21. for(int i = 0; i < st.length()-1; i++) {
  22. if(result[i] != result[i+1]){
  23. st1++;
  24. }
  25. }
  26. int[] sr = new int[st1];
  27. int[] sr2 = new int[st1];
  28. int t = 0;
  29. for(int i = 0; i <= st.length()-1; i++) {
  30. for(int j = 0; j < st1-1; j++){
  31. if(t == st1-1){
  32. break;
  33. }
  34. if(sr[j] != result[j]){
  35. sr[t] = result[j];
  36. t++;
  37. }
  38. }
  39. }
  40.  
  41. for(int i = 0; i <= st.length()-1; i++){
  42. for(int j = 0; j < st1; j++){
  43. if(result[i] == sr[j]){
  44. sr2[j] = sr2[j]+1;
  45. }
  46. }
  47. }
  48. int ss = 0;
  49. for(int i = 0;i<= st1-1; i++){
  50. for(int j = 0; j < st1-1; j++){
  51. if(sr2[j] > sr2[j+1]){
  52. ss = sr2[j];
  53. sr2[j] = sr2[j+1];
  54. sr2[j+1] = ss;
  55. }
  56. }
  57. }
  58. for(int i = 0; i < st1; i++) {
  59. System.out.println(sr[i]+" "+sr2[i]);
  60. }
  61. }
  62. }
Success #stdin #stdout 0.15s 58860KB
stdin
AAABBC
stdout
65 0
65 3
0 3