안녕하세요. 오늘은 섬의 개수를 셀 거예요.

문제

https://www.acmicpc.net/problem/9468

아이디어

인접한 두 수의 차이는 최대 1입니다.
그러므로 A_i<A_i+1인 i의 개수를 세어주면 됩니다.

소스코드

#include <iostream>
#define ll long long
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll T, tc, prv, now, i;

    cin >> T;
    while (T--)
    {
        ll ans = 0;
        cin >> tc >> prv;
        for (i = 2; i <= 15; i++)
        {
            cin >> now;
            if (prv < now) ans++;
            prv = now;
        }
        cout << tc << ' ' << ans << "\n";
    }
}


감사합니다.

0개의 댓글