🗒 17608번 문제
📌 막대기를 오른쪽에서 바라봤을 때 보이는 막대기를 찾아라
1️⃣ 왼쪽부터 보이는 막대기를 찾기 보단 오른쪽에서 보이는 막대기를 찾자!
2️⃣ 맨 왼쪽 막대기를 'top'으로 두고 해당 막대기보다 더 큰 막대기가 있다면 'top'를 갱신해주기
3️⃣ 'top'보다 크다면 해당 sticks값을 count하기 -> 'top'과 같은 건 세지 않기, 보이지 않기에❗️
4️⃣ count한 Stick를 출력하기
➰ 코드로 나타낸 17608번 ➰
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int stickNumber = 0, countStick = 1;
cin >> stickNumber;
int sticks[stickNumber];
for (int i = 0; i < stickNumber; i++)
cin >> sticks[i];
int top = sticks[stickNumber-1];
for (int i = stickNumber-2; i >= 0; i--) {
if(sticks[i] > top){
countStick++;
top = sticks[i];
}
}
cout << countStick << endl;
}