1 条题解
-
0
思路
维护连续长度,在首次达到k时输出,含k=1和末尾达标。按题面规定的输入输出协议处理;数据、边界和算法核验记录保存在本批教师资料。
参考程序(C++11)
#include <bits/stdc++.h> using namespace std; long long gcdll(long long a,long long b){while(b){long long t=a%b;a=b;b=t;}return a;} int main(){ios::sync_with_stdio(false);cin.tie(nullptr);const int p=1148; int k;string s;cin>>k>>s;int run=0;char last=0;for(char c:s){run=c==last?run+1:1;last=c;if(run>=k){cout<<c;return 0;}}cout<<"No"; cout<<"\n";return 0;}
- 1