```
백준 20674번 통계자료 빼기 C++ 구현해보기
```

이번 글을 통해 배워갈 내용
- 백준 20674번 풀이
https://www.acmicpc.net/problem/20674
20674번: Statistics
Coronavirus cases are now rising very fast in Neverland. The rise is mainly caused by a new variant of the virus which is spreading more rapidly than the original version. People are frustrated by seeing another pick in the statistics, while at the same ti
www.acmicpc.net
백준 20674번은
난이도 쉬움쉬움 등급의 문제로서
날짜 N이 주어지고
날짜 N 만큼 통계자료가 주어집니다.
각 날짜의 자료는 그 전날의 날짜중 가장 작은 날짜보다 더 적거나 같아야 하며
그렇지 않다면
그 초과분 만큼 지워줘야합니다.
지우는 초과분을 구하는 문제입니다.
30분 정도 위에 링크를 방문하셔서 풀어보시고
안풀리시는 경우에만 아래 해답을 봐주시면 감사하겠습니다.
day 만큼 반복해서 날짜를 입력받고
비교해서
같거나 작으면
현재 최소 값을 교체해주고
아니라면
결과 값에 해당되는 초과분 만큼 더해줍니다.
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>
int main()
{
std::cin.tie(NULL);
std::ios::sync_with_stdio(false);
/* number of the coming days */
int32_t days;
std::cin >> days;
std::cin.ignore();
int32_t curMin = INT32_MAX;
int32_t minManipulation = 0;
for (int32_t i = 0; i < days; i++)
{
/*number of new cases at the i-th day.*/
int32_t newCases;
std::string inputStr;
std::getline(std::cin, inputStr);
std::stringstream ss(inputStr);
ss >> newCases;
if (newCases <= curMin)
{
curMin = newCases;
}
else
{
minManipulation += (newCases - curMin);
}
}
std::cout << minManipulation;
}
읽어주셔서 감사합니다
무엇인가 얻어가셨기를 바라며
오늘도 즐거운 코딩하시길 바랍니다 ~ :)
참조 및 인용
C++ Primer
Introduction to Algorithms
https://codemasterkimc.tistory.com/35
C++ 이론을 배울수 있는 곳 정리
개요 C++을 배우는 책, 강의, 블로그, 링크 등을 공유합니다. (링크 및 간략한 설명을 하였으나 만약 원작자가 링크를 거는것을 원치 않을 경우 연락주시기 바랍니다.) 서적 https://www.amazon.com/Prime
codemasterkimc.tistory.com
https://codemasterkimc.tistory.com/50
300년차 개발자의 좋은 코드 5계명 (Clean Code)
이번 글을 통해 배워갈 내용 좋은 코드(Clean Code)를 작성하기 위해 개발자로서 생각해볼 5가지 요소를 알아보겠습니다. 개요 좋은 코드란 무엇일까요? 저는 자원이 한정적인 컴퓨터 세상에서 좋
codemasterkimc.tistory.com
'C++ > C++ 알고리즘' 카테고리의 다른 글
| 백준 15700번 타일채우기4 C++ 구현해보기 (0) | 2021.09.10 |
|---|---|
| 백준 2780번 비밀번호 C++ 구현해보기 (0) | 2021.09.09 |
| 백준 20673번 C++ 구현해보기 (0) | 2021.09.05 |
| 백준 1012번 유기농 배추 C++ 구현해보기 (0) | 2021.09.05 |
| 백준 2163번 초콜릿자르기 C++ 구현해보기 (0) | 2021.09.04 |