코딩테스트/프로그래머스
[레벨 2] 주식가격
marmelo12
2021. 9. 29. 14:01
반응형
#include <string>
#include <vector>
using namespace std;
vector<int> solution(vector<int> prices) {
vector<int> answer;
bool exit;
int count,Len = prices.size(),i,j;
for(i = 0; i < Len; ++i)
{
count = 1;
for(j = i + 1; j < Len - 1; ++j)
{
if(prices[i] > prices[j])
break;
else
++count;
}
if(j == Len) // 마지막 주가. 비교대상이 없으므로 0
{
answer.push_back(0);
break;
}
answer.push_back(count);
}
return answer;
}
반응형