본문 바로가기
ALGORITHM/Implement

[JAVA] 백준 10871번

by sjs_2215 2019. 9. 1.

https://www.acmicpc.net/problem/10871

 

문제 재정의:

수열 중 주어진 숫자보다 작은 수를 출력

 

생각한 것:

배열보다 큐로 하는 게 더 깔끔하다고 생각

 

코드:

 

package till;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = null;

        st = new StringTokenizer(br.readLine()); //공백 기준으로 나눔
          int n = Integer.parseInt(st.nextToken()); //수열 n개
           int x = Integer.parseInt(st.nextToken()); //x보다 작은 수

           int check=0;
           LinkedList nums = new LinkedList(); //수열 - 큐로 구현

        st = new StringTokenizer(br.readLine());
        for(int i=0;i<n;i++){

            check=Integer.parseInt(st.nextToken());
        if(check<x){
            nums.offer(check);
        }
        }

        while(!nums.isEmpty()){
            System.out.print(nums.poll()+" ");
        }


    }
}

'ALGORITHM > Implement' 카테고리의 다른 글

[JAVA] 백준 1789번  (0) 2019.09.01
[JAVA] 백준 2455번  (0) 2019.08.25
[JAVA] 백준 1173번  (0) 2019.08.17
[JAVA] 백준 1592번  (0) 2019.08.17
[JAVA] 프로그래머스 가장 큰 수  (0) 2019.07.15

Comments