[BOJ 2870] ์ˆ˜ํ•™์ˆ™์ œ

 

1. ๋ฌธ์ œ : https://www.acmicpc.net/problem/2870

 

2. ํ’€์ด

์ •๊ทœํ‘œํ˜„์‹

 

3. ์ฝ”๋“œ

package baekjoon;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.math.BigDecimal;
import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String str = "";
        String regex = "([\\d]+)";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher;

        int N = Integer.parseInt(br.readLine());
        ArrayList<BigDecimal> arr = new ArrayList<BigDecimal>();
        for(int i=0; i<N; i++) {
            str = br.readLine();
            matcher = pattern.matcher(str);
            while(matcher.find()) {
                arr.add(new BigDecimal(matcher.group()));
            }
        }
        arr.sort(Comparator.naturalOrder());
        for(BigDecimal val : arr) {
            bw.write(val+"");
            bw.newLine();
        }

        bw.flush();
    }
}
  • ๋„ค์ด๋ฒ„ ๋ธ”๋Ÿฌ๊ทธ ๊ณต์œ ํ•˜๊ธฐ
  • ๋„ค์ด๋ฒ„ ๋ฐด๋“œ์— ๊ณต์œ ํ•˜๊ธฐ
  • ํŽ˜์ด์Šค๋ถ ๊ณต์œ ํ•˜๊ธฐ
  • ์นด์นด์˜ค์Šคํ† ๋ฆฌ ๊ณต์œ ํ•˜๊ธฐ