給定一個字符串,在字符串中找到第一個連續出現至少k次的字符。ios
3 abcccaaab
c
1 #include<iostream> 2 #include<cstring> 3 using namespace std; 4 int main() 5 { 6 char a[300000] ; 7 int k, num = 1; 8 cin >> k; 9 cin >> a; 10 int l = strlen(a); 11 for (int i = 0; i < l; ++i) 12 { 13 14 15 if (a[i] == a[i + 1]) 16 { 17 ++num; 18 } 19 else 20 { 21 num = 1; 22 } 23 if (num >= k) 24 { 25 cout << a[i] << endl; 26 return 0; 27 } 28 } 29 30 cout << "No"<<endl; 31 return 0; 32 }