Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
115585 胡海峰老师 出现k次的字符 C++ Accepted 1 MS 280 KB 659 2025-03-31 20:26:52

Tests(10/10):


Code:

#include <iostream> #include <string> using namespace std; int main() { int k; string s; cin >> k; // 读取k值 cin >> s; // 读取字符串 int n = s.length(); for (int i = 0; i < n; ++i) { int count = 1; // 计数当前字符的连续出现次数 while (i + 1 < n && s[i] == s[i + 1]) { count++; i++; } if (count >= k) { // 如果连续出现次数达到或超过k cout << s[i] << endl; // 输出该字符 return 0; } } cout << "No" << endl; // 如果没有找到连续出现至少k次的字符 return 0; }