8 条题解

  • 0
    @ 2023-8-1 15:39:53

    #include <iostream> #include <string>

    char findFirstCharacter(int k, const std::string& s) { int count = 1; char prev = s[0];

    for (int i = 1; i < s.length(); i++) {
        if (s[i] == prev) {
            count++;
        } else {
            prev = s[i];
            count = 1;
        }
    
        if (count >= k) {
            return prev;
        }
    }
    
    return 'N'; // 如果没有符合条件的字符,返回'N'
    

    }

    int main() { int k; std::string s;

    std::cin >> k;
    std::cin.ignore(); // 忽略换行符
    std::getline(std::cin, s);
    
    char result = findFirstCharacter(k, s);
    if (result == 'N') {
        std::cout << "No" << std::endl;
    } else {
        std::cout << result << std::endl;
    }
    
    return 0;
    

    }

    信息

    ID
    977
    时间
    1000ms
    内存
    256MiB
    难度
    4
    标签
    递交数
    69
    已通过
    28
    上传者