题解 | #字符串最后一个单词的长度#
字符串最后一个单词的长度
https://www.nowcoder.com/practice/8c949ea5f36f422594b306a2300315da?tpId=37&tqId=21224&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=
明天联发科笔试。刷一下C语言哈哈
#include <stdio.h>
int main(int argc, char *argv[]) {
int res = 0;
char ch;
char blank = ' ';
while ((ch = getchar()) != '\n') {
if (ch != blank) {
++res;
} else {
res = 0;
}
}
printf("%d\n", res);
return 0;
}