Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Locale;
- import java.util.Map;
- import java.util.Scanner;
- import java.math.BigDecimal;
- public class TestLargestNums {
- public static void main(String[] args) {
- Locale.setDefault(Locale.ROOT);
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- String word = "";
- BigDecimal num = BigDecimal.valueOf(0);
- Map<String, BigDecimal> hm = new HashMap<String, BigDecimal>();
- sc.nextLine();
- for (int i = 0; i < n; i++) {
- word = sc.nextLine();
- num = new BigDecimal(word);
- hm.put(word, num);
- }
- List<BigDecimal> newList = new ArrayList<>();
- for (Map.Entry<String, BigDecimal> entry : hm.entrySet()) {
- // String key = entry.getKey();
- BigDecimal value = entry.getValue();
- newList.add(value);
- Collections.sort(newList);
- Collections.reverse(newList);
- }
- if (newList.size() >= 3) {
- for (int i = 0; i < 3; i++) {
- System.out.println(newList.get(i));
- }
- }
- else if(newList.size() == 2){
- for (int i = 0; i < 2; i++) {
- System.out.println(newList.get(i));
- }
- }
- else if (newList.size() == 1) {
- for (int i = 0; i < 1; i++) {
- System.out.println(newList.get(i));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement