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