ZJANS

c657. 最長連續字母

Easy Last Update: 2026/01/22

解法一

✅ 完整代碼

評分結果(參考) : AC (1ms, 316KB)

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

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string s;
    while(cin >> s){
        int cnt=1, ans=1;
        char c = s[0];
        for(int i=1; i<s.size(); i++){
            if(s[i] == s[i-1]){
                cnt++;
                if(cnt > ans){
                    ans = cnt;
                    c = s[i];
                }
            }
            else{
                cnt = 1;
            }
        }
        cout << c << " " << ans << "\n";
    }
    
    return 0;
}