"보다 작은"은 주어진 수를 포함하지 않는다.
Bash
bash
read n x
read arr
for i in $arr; do
if [ $i -lt $x ]; then
echo -n $i" "
fi
done
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
C
c
#include <stdio.h>
int main(void) {
int n, x;
scanf("%d %d", &n, &x);
int arr[n];
for (int i=0; i<n; i++) {
scanf("%d", &arr[i]);
}
for (int i=0; i<n; i++) {
if (arr[i] < x) {
printf("%d ", arr[i]);
}
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Node.js
javascript
let [n, x, ...arr] = require("fs").readFileSync(0).toString().trim().split(/ |\n/).map(Number);
console.log( arr.filter(i => i < x).join(" ") );
1
2
2
PHP
php
<?php
list ($n, $x) = explode(" ", trim(fgets(STDIN)));
$arr = explode(" ", trim(fgets(STDIN)));
$cnt = 0;
foreach ($arr as $a) {
if ($a < $x) { echo "$a "; }
}
?>
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
Python3
python
n, x = map(int, input().split())
arr = map(int, input().split())
arr = list(filter(lambda i: i < x, arr))
print( " ".join(map(str, arr)) )
1
2
3
4
2
3
4
Python은 lambda
를 지원한다.
Ruby
ruby
n, x = gets.chomp.split().map {|i| i.to_i}
arr = gets.chomp.split().map {|i| i.to_i}
puts arr.select {|i| i < x}.join(" ")
1
2
3
2
3
Comments
Not supported comment edit and upvote
You can do it on this page if you want.