package com.codegym.task.task18.task1804;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;
/*
Rarest bytes
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String sAge = reader.readLine();
// String sAge="/home/r00t/test/file3";
FileInputStream inputStream = new FileInputStream(sAge);
reader.close();
TreeMap<Integer,Integer> map=new TreeMap<Integer,Integer>();
boolean check = true;
Integer compare = null;
while (inputStream.available() > 0) //as long as there are unread bytes
{
int data = inputStream.read(); //Read the next byte
if (map.containsKey(data)) {
int value = map.get(data);
map.put(data,++value);
}
else {
map.put(data, 1);
}
}
inputStream.close();
for(Map.Entry m:map.entrySet()){
if (check) {
compare = Integer.parseInt(m.getValue().toString());
check = false;
}
if (compare==Integer.parseInt(m.getValue().toString())) {
// Integer condition = Integer.parseInt(m.getKey().toString());
// Integer condition2 = 20;
// if (condition > condition2) {
System.out.print(m.getKey() + " ");
// }
}
}
}
}
output all keys who's value's are equal to min and still the task failed??
Resolved
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
ilian44
29 November 2019, 07:19
Thanks, dude! I managed to solve it!
0
Guadalupe Gagnon
29 November 2019, 01:45
Tree maps sort by key, so when you set compare at line 54 you are setting it to the value of the 'lowest' key. This key has a very low chance of actually being the least repeated key in the file.
To solve this task you need to find the lowest value and output the key (or keys) that match that value.
+1