#include<stdio.h>
#include<string.h>
int main(void){
char str[5000]={0};
char *p =NULL;fgets(str,sizeof(str),stdin);
p =strrchr(str,' ');if(p !=NULL){
p = p +1;printf("%d",strlen(p)-1);}else{printf("%d",strlen(str)-1);}}
解法思路2:
#include <stdio.h>
int main(){
char str;
short int x =-1, i =0;while(scanf("%c",&str)!=EOF){if(str ==' ')
x = i;
i++;}
x=i - x -2;printf("%d", x);return0;}