牛客编程题(C语言):HJ1 字符串最后一个单词的长度

https://www.nowcoder.com/ta/huawei/
https://www.nowcoder.com/exam/oj/ta?tpId=37

https://www.nowcoder.com/practice/8c949ea5f36f422594b306a2300315da

提交代码

#include <stdio.h>

int main() {
    char ch[5000];
    gets(ch);//带空格输入字符串,遇回车结束
    int i=0,len=0;
    while(ch[i]!='\0') {
        if(ch[i] == ' '){
            len=-1;
        }
        len++;
        i++;
    }
    printf("%d\n",len);
    return 0;
}

执行结果

posted @ 2022-05-15 15:56  孤舟浮岸  阅读(103)  评论(0)    收藏  举报