Coding Test - cpp/Greedy
[백준 10162: 전자레인지] - C++
에드윈H
2021. 3. 25. 17:49
10162번: 전자레인지
3개의 시간조절용 버튼 A B C가 달린 전자레인지가 있다. 각 버튼마다 일정한 시간이 지정되어 있어 해당 버튼을 한번 누를 때마다 그 시간이 동작시간에 더해진다. 버튼 A, B, C에 지정된 시간은
www.acmicpc.net
#pragma once
#include <iostream>
using namespace std;
int main() {
int a = 300;
int b = 60;
int c = 10;
int t;
int cnt[3] = { 0 };
cin >> t;
bool bImpossible = false;
while (t>0)
{
if (a <= t)
{
cnt[0] += 1;
t -= a;
}
else if (b <= t)
{
cnt[1] += 1;
t -= b;
}
else if (c <= t)
{
cnt[2] += 1;
t -= c;
}
else
{
bImpossible = true;
break;
}
}
if (bImpossible)
cout << -1 << endl;
else
{
cout << cnt[0]<<" "<< cnt[1] << " "<< cnt[2]<< endl;
}
return 0;
}//end of main