![[백준 / BOJ] 10871번 X보다 작은 수 (C++, Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbXwo0w%2FbtrJgx1bVik%2F85TyZuoQFiu4xl2zl8k4mk%2Fimg.png)
[백준 / BOJ] 10871번 X보다 작은 수 (C++, Python)◎ 자료구조와 알고리즘/백준(BOJ) 문제풀이2021. 8. 23. 23:52
Table of Contents
반응형
링크 : https://www.acmicpc.net/problem/10871
10871번: X보다 작은 수
첫째 줄에 N과 X가 주어진다. (1 ≤ N, X ≤ 10,000) 둘째 줄에 수열 A를 이루는 정수 N개가 주어진다. 주어지는 정수는 모두 1보다 크거나 같고, 10,000보다 작거나 같은 정수이다.
www.acmicpc.net
문제

문제 풀이
반복문 안에 조건문을 넣으면 간단하게 풀리는 문제다.
C++ 코드 전문
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int main() | |
{ | |
int N, X, input; | |
std::cin >> N >> X; | |
for (int i=0; i<N; i++) | |
{ | |
std::cin >> input; | |
if (X > input) | |
std::cout << input << " "; | |
} | |
} |
Python 코드 전문
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N, X = map(int, input().split()) | |
val = list(map(int, input().split())) | |
for i in range(N): | |
if X > val[i]: | |
print(f"{val[i]} ", end="") |
소감
반응형
'◎ 자료구조와 알고리즘 > 백준(BOJ) 문제풀이' 카테고리의 다른 글
[백준 / BOJ] 10951번 A+B - 4 (C++, Python) (0) | 2021.08.24 |
---|---|
[백준 / BOJ] 10952번 A+B - 5 (C++, Python) (0) | 2021.08.24 |
[백준 / BOJ] 2439번 별 찍기 - 2 (C++, Python) (0) | 2021.08.23 |
[백준 / BOJ] 2438번 별 찍기 - 1 (C++, Python) (0) | 2021.08.23 |
[백준 / BOJ] 11022번 A+B - 8 (C++, Python) (0) | 2021.08.23 |
@Reo :: 코드 아카이브
자기계발 블로그