문제 출처: www.acmicpc.net/problem/10871
10871번: X보다 작은 수
첫째 줄에 N과 X가 주어진다. (1 ≤ N, X ≤ 10,000) 둘째 줄에 수열 A를 이루는 정수 N개가 주어진다. 주어지는 정수는 모두 1보다 크거나 같고, 10,000보다 작거나 같은 정수이다.
www.acmicpc.net
1. 코드
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> | |
using namespace std; | |
int main(void) | |
{ | |
int n, x; | |
cin >> n >> x; | |
while(n--) | |
{ | |
int a; | |
cin >> a; | |
if(a < x) | |
cout << a << " "; | |
} | |
return 0; | |
} |
2. 풀이
int n, x;
cin >> n >> x;
n과 x를 입력받는다.
while(n--)
그리고 n만큼 반복을 시킨다.
int a;
cin >> a;
그리고 n만큼 a를 입력을 한 뒤에
if(a < x)
cout << a << " ";
만약 a의 값이 x보다 작다면 출력을 한 뒤 띄어쓰기를 해준다.
'컴퓨터 > 백준 알고리즘' 카테고리의 다른 글
백준 알고리즘 10951번: A+B - 4 [C++] (0) | 2020.12.19 |
---|---|
백준 알고리즘 10952번: A+B - 5 [C++] (0) | 2020.12.18 |
백준 알고리즘 2439번: 별 찍기 - 2 [C++] (0) | 2020.12.15 |
백준 알고리즘 11021번: A+B - 7 [C++] (0) | 2020.12.08 |
백준 알고리즘 2742번: 기찍 N [C++] (0) | 2020.12.07 |