본문 바로가기
알고리즘/구름

[ 구름 / 단순 구현 ] 고장난 컴퓨터 풀이

by 뎁꼼 2020. 6. 27.

1. 문제


 

 

구름LEVEL

코딩테스트에서 가장 높은 비중을 차지하는 알고리즘 문제를 제작하고 풀이할 수 있는 온라인 저지 서비스입니다. 기업에서 선호하는 C, C++, 파이썬(Python), 자바(Java), 자바스크립트(Javascript) 이��

level.goorm.io

 

 

2. 소스코드


 

 

 

소스코드

#include <iostream>
#include <vector>
using namespace std;

int n, c;
vector<int>input;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	
	cin >> n >> c;
	input.resize(n);
	for(int i = 0 ; i < n ; ++i)
		cin >> input[i];

	int idx = 0;
	int time = 0;
	int clearTime = 0;
	int word = 0;
	
	while(++time){
		if(input[idx] == time) {
			idx++;
			word++;
			clearTime = time + c;
			if(idx > input.size() - 1) break;
		}
		if(time == clearTime) word = 0;
	}
	cout << word << '\n';
 
	return 0;
}