티스토리 뷰
https://www.acmicpc.net/problem/1059
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int L, n, cnt = 0;
cin >> L;
int arr[L]; //집합 S에 포함된 정수
for(int i=0; i<L; i++)
cin >> arr[i];
cin >> n;
sort(arr, arr+L); //집합 S 오름차순 정렬
int start = 0, end = 0;
for(int i=0; i<L; i++)
{
if(arr[i] > n)
{
start = arr[i-1];
end = arr[i];
break;
}
else if(arr[i] == n)
{
//n이 S에 포함되어 있는 경우
cout << 0 << '\n';
return 0;
}
}
for(int i=start+1; i<end; i++)
{
for(int j=i+1; j<end; j++)
{
if(i<=n && n<=j)
cnt++;
}
}
cout << cnt << '\n';
return 0;
}
'PS > BOJ C++' 카테고리의 다른 글
2108번 - 통계학 (0) | 2021.10.10 |
---|---|
11653번 - 소인수분해 (0) | 2021.10.06 |
3036번 - 링 (0) | 2021.09.26 |
9012번 - 괄호 (0) | 2021.09.20 |
11508번 - 2+1 세일 (0) | 2021.09.16 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 1182
- 1715
- 자료구조
- 싸피
- 프로그래머스
- 수학
- 1759
- 파이썬
- 빌림
- 조합
- 브루트포스
- 딕셔너리
- 10816
- 2805
- 스택
- 백준
- 삼성청년소프트웨어아카데미
- 11051
- 10845
- 1764
- 1358
- heapq
- 10815
- 백트래킹
- 10971
- 17478
- dp
- 덱
- 큐
- 러스트
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
글 보관함