题解 | [NOIP2018]标题统计
#include <stdio.h> #include <string.h> int main() { char s[1000]; // 假设标题最多不超过999个字符 fgets(s, sizeof(s), stdin); // 读取输入的标题 int count = 0; for (int i = 0; s[i] != '\0'; i++) { if (s[i] != ' ' && s[i] != '\n') { // 排除空格和换行符 count++; } } printf("%d\n", count); // 输出有效字符数 return 0; }