字符串最后一个单词的长度

来源:互联网 发布:淘宝怎么买彩票 编辑:程序博客网 时间:2024/06/10 02:41

如题意,代码如下:


#include <stdio.h>#include <string.h>#include <stdlib.h>#include <iostream>using namespace std;int wordlength(char a[]){char temp[200];int count=0;int len=strlen(a);for(int i=0;i<len;i++)temp[i]=a[len-1-i];for(int i=0;i<len;i++)if(temp[i]==' ')break;elsecount++;return count;}int main(){char a[200];gets(a);if (strlen(a)<128)cout<<wordlength(a)<<endl;system("pause");return 0;}


0 0
原创粉丝点击