Run ID:117098

提交时间:2025-04-13 16:57:51

#include <iostream> #include <string> using namespace std; int main() { int k; string s; // 读取输入 cin >> k; cin >> s; // 初始化变量 int count = 1; // 当前字符的连续出现次数 char currentChar = s[0]; // 当前字符 // 遍历字符串 for (size_t i = 1; i < s.length(); ++i) { if (s[i] == currentChar) { // 如果当前字符与前一个字符相同,增加计数器 ++count; if (count == k) { // 如果连续出现次数达到k,输出当前字符并结束程序 cout << currentChar << endl; return 0; } } else { // 如果当前字符与前一个字符不同,重置计数器和当前字符 currentChar = s[i]; count = 1; } } // 如果遍历完整个字符串都没有找到符合条件的字符,输出"No" cout << "No" << endl; return 0; }