Posted on 2012-08-18 21:59
hoshelly 閱讀(209)
評論(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;
}