fork download
  1.  
  2. import java.util.HashMap;
  3. import java.util.Map;
  4. import java.util.ArrayList;
  5.  
  6. /*
  7. Нам повторы не нужны
  8. */
  9.  
  10. class Solution {
  11. public static Map<String, String> createMap() {
  12. //напишите тут ваш код
  13. Map<String, String> map = new HashMap<>();
  14. map.put("Сидоров", "Андрей");
  15. map.put("Петров", "Андрей");
  16. map.put("Иванов", "Олег");
  17. map.put("Курочкин", "Дмитрий");
  18. map.put("Куклачев", "Филлип");
  19. map.put("Потапенко", "Зинаида");
  20. map.put("Гагарин", "Алексей");
  21. map.put("Титов", "Алексей");
  22. map.put("Немченко", "Татьяна");
  23. map.put("Кудряшова", "Ирина");
  24.  
  25. return map;
  26. }
  27.  
  28. public static void removeTheFirstNameDuplicates(Map<String, String> map) {
  29. //напишите тут ваш код
  30. ArrayList<String> list = new ArrayList<>();
  31. list.addAll(map.values());
  32. for (String v : list) {
  33. System.out.println(v);
  34. }
  35. for (String value : list) {
  36. int count = Collections.frequency(value, list);
  37.  
  38. if (count > 1) {
  39. removeItemFromMapByValue(value);
  40. }
  41. }
  42. System.out.println("МАГИЯ............");
  43. for (String v : list) {
  44. System.out.println(v);
  45. }
  46. }
  47.  
  48. public static void removeItemFromMapByValue(Map<String, String> map, String value) {
  49. Map<String, String> copy = new HashMap<>(map);
  50. for (Map.Entry<String, String> pair : copy.entrySet()) {
  51. if (pair.getValue().equals(value)) {
  52. map.remove(pair.getKey());
  53. }
  54. }
  55. }
  56.  
  57. public static void main(String[] args) {
  58. removeTheFirstNameDuplicates(createMap());
  59. }
  60. }
  61.  
Compilation error #stdin compilation error #stdout 0.04s 2184192KB
stdin
Standard input is empty
compilation info
Main.java:36: error: cannot find symbol
            int count = Collections.frequency(value, list);
                        ^
  symbol:   variable Collections
  location: class Solution
Main.java:39: error: method removeItemFromMapByValue in class Solution cannot be applied to given types;
            	removeItemFromMapByValue(value);	
            	^
  required: Map<String,String>,String
  found: String
  reason: actual and formal argument lists differ in length
2 errors
stdout
Standard output is empty