【題解】ZeroJudge a465: 12405 – Scarecrow

【題目敘述】https://zerojudge.tw/ShowProblem?problemid=a465
【解題想法】Greedy

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

int t, Case, n, ans, r;
string s;

int main(){
    cin >> t;
    while (t--){
        cin >> n;
        cin >> s;
        ans = 0;
        r = -1;
        for (int i = 0; i < n; i++){
            if (s[i] == '.' && i > r){
                r = i+2;
                ans++;
            }
        }
        Case++;
        cout << "Case " << Case << ": " << ans << "\n";
    }
}
分享本文 Share with friends