티스토리 뷰

PS/BOJ C++

1059번 - 좋은 구간

zpqmdh 2021. 10. 3. 02:28

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

 

1059번: 좋은 구간

[9, 10], [9, 11], [9, 12], [10, 11], [10, 12]

www.acmicpc.net

#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
링크
«   2024/09   »
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
글 보관함