天之道

享受编程的乐趣。
posts - 118, comments - 7, trackbacks - 0, articles - 0
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

计算最长空格序列的长度

Posted on 2012-08-18 21:59 hoshelly 阅读(197) 评论(0)  编辑 收藏 引用 所属分类: Programming
编写一程序,确定一个给定字符串中最长的空格序列的长度。

#include<stdio.h>
#include<string.h>
#define N 1000
int main()
{
    char a[N];
    int i,j,k=0,count[100]={0},max;
    printf("Input the a string: "); //输入字符串
    gets(a);
    for(i=0;a[i]!=0;i++)
    {
        while(a[i++] == ' ')
        {
            count[k]++;
            if(a[i+1]!=' ')
                k++;
        }
    }
    for(j=0;j<k;j++)
    {
        max=count[0];
        if(count[j]<count[j+1])
            max=count[j+1];
    }
    printf("%d\n",max);
    return 0;
}
    

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理