题解 | #[NOIP2018]标题统计#
[NOIP2018]标题统计
https://www.nowcoder.com/practice/b14b87bc6a4547a6839e0a5867c98dba
#include <iostream> #include <string> using namespace std; int countNonWhitespaceCharacters(const string& title) { int count = 0; for (char c : title) { if (c != ' ' && c != '\n') { ++count; } } return count; } int main() { string title; getline(cin, title); // 使用getline确保能够读取包含空格的整行 int result = countNonWhitespaceCharacters(title); cout << result << endl; return 0; }#c++#