题解 | #字符串最后一个单词的长度#
字符串最后一个单词的长度
https://www.nowcoder.com/practice/8c949ea5f36f422594b306a2300315da
#include <stdio.h> #include <string.h> #define N 5010 char s[N]; int main() { gets(s); int cnt = 0; for (int i = 0; i < strlen(s); i ++ ) { if (s[i] != ' ') cnt ++ ; else cnt = 0; } printf("%d", cnt); return 0; }