Skip to content

Instantly share code, notes, and snippets.

@chathurawidanage
Created August 21, 2016 07:51
Show Gist options
  • Save chathurawidanage/a9db637d51eae1ad7b4c82b34ff566b3 to your computer and use it in GitHub Desktop.
Save chathurawidanage/a9db637d51eae1ad7b4c82b34ff566b3 to your computer and use it in GitHub Desktop.
import java.util.*;
/**
* @author Chathura Widanage
*/
public class SortR {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
String line;
Map<Float,String> mapping=new HashMap<>();//assuming there won't be any similar cor coefficients
while((line=scanner.nextLine())!=null && !line.equals("exit")){
String sub=line.substring(5,line.length()-1);
String parts[]=sub.split(" -> ");
mapping.put(Float.parseFloat(parts[0]),parts[1]);
}
List<Float> kets=new ArrayList<>(mapping.keySet());
Collections.sort(kets);
Collections.reverse(kets);
kets.forEach(key->{
System.out.println(String.format("%s [%f]",mapping.get(key),key));
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment