Created
August 21, 2016 07:51
-
-
Save chathurawidanage/a9db637d51eae1ad7b4c82b34ff566b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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