medon3

Untitled

Jun 5th, 2022
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. import com.sun.source.tree.Tree;
  2.  
  3. import java.util.*;
  4. import java.util.stream.Collectors;
  5.  
  6. public class JustCount {
  7.  
  8.  
  9. public static void main(String[] args) {
  10.  
  11. Scanner sc = new Scanner(System.in);
  12.  
  13. String input = sc.nextLine();
  14. String inputArr[] = input.split("");
  15.  
  16.  
  17. TreeMap<Character, Integer> countLower = new TreeMap<>();
  18. TreeMap<Character, Integer> countUpper = new TreeMap<>();
  19. TreeMap<Character, Integer> countNonLetters = new TreeMap<>();
  20. // List<Character> lowerCaseLetters = new ArrayList<>();
  21. // List<Character> upperCaseLetters = new ArrayList<>();
  22. // List<Character> nonLetters = new ArrayList<>();
  23. boolean b1 = false;
  24. boolean b2 = false;
  25.  
  26.  
  27. for (int i = 0; i < inputArr.length; i++) {
  28. char symbol = inputArr[i].charAt(0);
  29. b1 = Character.isLowerCase(symbol);
  30. b2 = Character.isUpperCase(symbol);
  31. if (b1) {
  32. if (!countLower.containsKey(symbol)) {
  33. countLower.put(symbol, 1);
  34. } else {
  35. countLower.put(symbol, countLower.get(symbol) + 1);
  36. }
  37. } else if (b2) {
  38. if (!countUpper.containsKey(symbol)) {
  39. countUpper.put(symbol, 1);
  40. } else {
  41. countUpper.put(symbol, countUpper.get(symbol) + 1);
  42. }
  43.  
  44. } else {
  45. if (!countNonLetters.containsKey(symbol)) {
  46. countNonLetters.put(symbol, 1);
  47. } else {
  48. countNonLetters.put(symbol, countNonLetters.get(symbol) + 1);
  49. }
  50. }
  51. }
  52.  
  53.  
  54. if (countNonLetters.size() == 0) {
  55. System.out.println("-");
  56. } else {
  57. int max = countNonLetters.values().stream().max(Integer::compare).get();
  58. for (var entry : countNonLetters.entrySet()) {
  59. if (entry.getValue() == max) {
  60. char maxChar = entry.getKey();
  61. System.out.print(maxChar + " ");
  62. System.out.print(max);
  63. System.out.println();
  64. break;
  65. }
  66. }
  67. }
  68.  
  69.  
  70. if (countLower.size() == 0) {
  71. System.out.println("-");
  72. } else {
  73. int maxLower = countLower.values().stream().max(Integer::compare).get();
  74. for (var entry : countLower.entrySet()) {
  75. if (entry.getValue() == maxLower) {
  76. char maxChar = entry.getKey();
  77. System.out.print(maxChar + " ");
  78. System.out.print(maxLower);
  79. System.out.println();
  80. break;
  81. }
  82. }
  83. }
  84.  
  85. if (countUpper.size() == 0) {
  86. System.out.println("-");
  87. } else {
  88. int maxUpper = countUpper.values().stream().max(Integer::compare).get();
  89. for (var entry : countUpper.entrySet()) {
  90. if (entry.getValue() == maxUpper) {
  91. char maxChar = entry.getKey();
  92. System.out.print(maxChar + " ");
  93. System.out.print(maxUpper);
  94. break;
  95. }
  96. }
  97. }
  98.  
  99. }
  100.  
  101. }
  102.  
  103.  
Advertisement
Add Comment
Please, Sign In to add comment