Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
117098 彭士宝 出现k次的字符 Python3 Compile Error 0 MS 0 KB 1022 2025-04-13 16:57:51

Tests(0/0):


Code:

#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; }


Run Info:

  File "Main.py", line 3
    using namespace std;
                  ^
SyntaxError: invalid syntax