题解 | #字符串最后一个单词的长度#
字符串最后一个单词的长度
http://www.nowcoder.com/practice/8c949ea5f36f422594b306a2300315da
#include "stdio.h" #include "string.h" int main(){ char str[5000] = {0}; char p = str; char m =str; int k = 0; fgets(str,sizeof(str),stdin); while(1){ if((p+1)=='\0'){break;} p++; } while(1){ if((p-1)==' '||*m==*p){break;} p--; k++; } printf("%d",k); return 0; }