Title: Finding the length of the last word in a string//Note:s="A"The return should be1//s=" "The return should be0//s="a"The return should be1#include <stdlib.h>#include <stdio.h>#include <string.h>intLengthoflastword (char*s) {int length=0;intI=0;intn = strlen (s); for(i=0; i<n;i++) {if(((' A '<=s[i]) && (s[I] <=' Z '))|| ((' A '<=s[i]) && (s[I] <=' Z '))) {length++; }if(s[I] = ="') {if(((' A '<=s[i+1]) && (s[i+1] <=' Z '))|| ((' A '<=s[i+1]) && (s[i+1] <=' Z '))) {length=0;printf("s[%d] = %d\ n", i+1,s[i+1]); } } }return length;}intMain () {Char*s1="H";intR1 = Lengthoflastword (S1);printf("Lengthoflastword is: %d\ n", R1);// 1Char*s2="Hello World Xiabodan";intr2 = Lengthoflastword (s2);printf("Lengthoflastword is: %d\ n", r2);// 8Char*S3=" ";intR3 = Lengthoflastword (S3);printf("Lengthoflastword is: %d\ n", R3);// 0Char*S4="H";intR4 = Lengthoflastword (S4);printf("Lengthoflastword is: %d\ n", R4);// 1}
[Leetcode]-length of last Word