CSES – Repetitions

迴圈、條件判斷

#include<bits/stdc++.h>
#define int long long
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
using namespace std;
signed main(){
    fastio;
    string s; cin>>s;
    int cnt = 1, ans = 0;
    char now = s[0];
    for(int i=1;i<s.size();i++){
        if(s[i] == now){
            cnt++;
            continue;
        }
        now = s[i];
        ans = max(ans, cnt);
        cnt = 1;
    }
    ans = max(ans, cnt);
    cout<<ans<<"\n";
    return 0;
}

相關文章

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *