【題解】Google Kick Start 2020 Round C – p1. Countdown

【題目敘述】https://codingcompetitions.withgoogle.com/kickstart/round/000000000019ff43/00000000003380d2

#include <bits/stdc++.h>
using namespace std;

int Case, t, n, k, a[200005];

int main(){
    cin >> t;
    while (t--){
        cin >> n >> k;
        int tmp = -1;
        int ans = 0;
        for (int i = 0; i < n; i++){
            cin >> a[i];
            if (a[i] == k) tmp = k-1;
            else if (a[i] == tmp) tmp--;
            else tmp = -1;
            if (tmp == 0){
                ans++;
                tmp--;
            }
        }
        Case++;
        cout << "Case #" << Case << ": " << ans << "\n";
    }
}
分享本文 Share with friends