跳到正文

题解

题解:P16922 [JLCPC 2026] 顺子

Studyer_and_OIer约 3 分钟
原文
文章信息与版本

文章信息

收录
2026年6月13日
更新
2026年6月14日
篇幅
约 3 分钟
题目
P16922

版本

  1. v1当前

水题。
首先是输入,可以用字符串存储,如果发现是数字就调用 stoi() 函数转化成数字,然后放到一个 bool 数组里,注意 A,J,Q,K 需要特判,这里的 A 可以处理成 1414。
然后打擂刷新答案即可。

C++
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define piii pair<pii, int>
#define pll pair<ll, ll>
#define plll pair<pll, ll>
#define pref static inline
#define fi first
#define se second
using namespace std;
const int MAXN=25;
int t,x;
string s;
bool flag[MAXN];
namespace heffo_hard{
    pref bool nums(string s){
        for(int i=0;i<s.size();++i){
            if(!isdigit(s[i]))return false;
        }
        return true;
    }
    pref void solve(){
        memset(flag,0,sizeof(flag));
        for(int i=1;i<=17;++i){
            cin>>s;
            if(nums(s)){
                if(stoi(s)==2)continue;
                flag[stoi(s)]=1;
            }else if(s=="A"){
                flag[14]=1;
            }else if(s=="J"){
                flag[11]=1;
            }else if(s=="Q"){
                flag[12]=1;
            }else if(s=="K")flag[13]=1;
        }
        int ans=0,cnt=0;
        for(int i=3;i<=14;++i){
            if(!flag[i]){
                ans=max(ans,cnt);
                cnt=0;
            }else cnt++;
        }
        ans=max(ans,cnt);//最后还要取max
        if(ans<5)cout<<0<<endl;
        else cout<<ans<<endl;
    }
};

signed main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>t;
    while(t--)
    heffo_hard::solve();
    return 0;
}
/*
*/
原文