728x90
https://www.acmicpc.net/problem/16396
16396번: 선 그리기
준용이의 조카 준섭이는 크레파스로 한 직선에 평행한 여러 개의 선분을 그리고 있었다. 준섭이의 모습을 보고 있던 준용이는 준섭이가 그린 모든 선들을 직선 좌표에 투사(projection)했을 때 투사된 선들의 길이 합이 궁금하였다. 준용이에게 잘 보여야하는 여러분은 준용이의 궁금증을 해결하기 위해 프로그램을 구현해주자.
www.acmicpc.net
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 N[10001] = { 0 }; | |
int main() { | |
int n; | |
int a, b; | |
int sum = 0; | |
cin >> n; | |
for (int i = 0; i < n; i++) { | |
cin >> a >> b; | |
for (; a < b; a++) { | |
N[a] = 1; | |
} | |
} | |
for (int i = 1; i <= 10000; i++) { | |
if (N[i] == 1) | |
sum++; | |
} | |
cout << sum; | |
return 0; | |
} |
신경써야하는 것
- 배열의 범위
'프로그래밍 > programmers&bj' 카테고리의 다른 글
[C++][알고리즘] 프로그래머스:: 쇠막대기 (0) | 2019.11.18 |
---|---|
[C++][알고리즘] 프로그래머스:: 기능개발 (0) | 2019.11.16 |
[C++][알고리즘] 백준 16395번 파스칼의 삼각형 (0) | 2019.09.22 |
[C++][알고리즘] 프로그래머스:: 예산 (0) | 2019.09.10 |
[C++][알고리즘] 백준 1813번 마지막한마디 (0) | 2019.09.01 |