为什么93分

tctm169 我以逍遥醉人间 2025-01-27 10:27:54 3

#include

#include

#include

std::string toLowerCase(const std::string& str) {

std::string result = str;

std::transform(result.begin(), result.end(), result.begin(),

               [](unsigned char c) { return std::tolower(c); });

return result;

} int countBrown(const std::string& str) {

std::string lowerStr = toLowerCase(str);

int count = 0;

size_t pos = 0;

while ((pos = lowerStr.find("brown", pos)) != std::string::npos) {

    if ((pos == 0 || !std::isalpha(lowerStr[pos - 1])) &&

        (pos + 5 == lowerStr.length() || !std::isalpha(lowerStr[pos + 5]))) {
        count++;

    }

    pos += 5;

}

return count;

}

int main() {

std::string line;

int totalCount = 0;

while (std::getline(std::cin, line)) {

    totalCount += countBrown(line);

}

std::cout << totalCount << std::endl;

return 0;

}

{{ vote && vote.total.up }}

共 1 条回复

root 站长

自己写代码试试。