题解 | #字符串最后一个单词的长度#
字符串最后一个单词的长度
https://www.nowcoder.com/practice/8c949ea5f36f422594b306a2300315da
#include <stdio.h>
#include <string.h>
//循环到最后,倒着找到空格为止
int main() {
int count;
char s[5000]={0};
scanf("%[^\n]", s);
//fgets(s, sizeof(s), stdin);
char *p=s;
while(*p!='\0'){
p++;
}
p--;
while(*p!=' '){
p--;
count++;
if(count==strlen(s)){
break;
}
}
printf("%d\n",count);
return 0;
}
OPPO公司福利 1059人发布
查看14道真题和解析
