Baekjoon Algorithm | Problem 10871: Less Than X

Source

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

Problem

Solve Baekjoon Online Judge problem 10871, Less Than X.

Input

Follow the input format and constraints given in the original problem statement.

Output

Print the answer required by the problem.

Sample Input 1

10 5 1 10 4 9 2 3 8 5 7 6

Sample Output 1

1 4 2 3

Algorithm Classification

  • Math
  • Implementation

Solution

import java.io.*;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        try (
                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        ) {
            StringTokenizer input1 = new StringTokenizer(br.readLine(), " ");
            final int n = Integer.parseInt(input1.nextToken());
            final int x = Integer.parseInt(input1.nextToken());

            StringTokenizer input2 = new StringTokenizer(br.readLine(), " ");
            for (int i = 0; i < n; i++) {
                int a = Integer.parseInt(input2.nextToken());
                if (a < x) {
                    bw.write(a + " ");
                }
            }

            bw.flush();
        }
    }
}