#include <stdio.h>
void printlongdanci(char[]);
int is_char(char);
int main (int argc, char *argv[])
{
char ch1[100];
printf("please input 1 line string:\n");
gets(ch1);
printf("the long danci is :");
printlongdanci(ch1);
system("pause");
return 0;
}
void printlongdanci(char ch[])
{
int i,j = 0,k = -2,temp_begin = 0,temp_end = 0;
int begin = 0,end;
int max = 0;
char c;
int str_len = strlen(ch);
for (i = 0; i< str_len; i++)
{
c = ch[i];
if (is_char(c))
{
j++;
}
else if (' ' == c)
{
if (j > max)
{
max =j;
end = i - 1;
begin = temp_begin;
}
temp_begin = i + 1;
temp_end = i -1;
j = 0;
}
else if ((c == '.' || c == ';') && ((ch[i+1]) == '\0'))
{
if (j > max) //并且此字符后面不能含有字符。则认为这个一个单词。
{
max =j;
end = i - 1;
begin = temp_begin;
}
temp_begin = i + 1;
temp_end = i -1;
j = 0;
}
else
{
;
}
}
for (i = begin; i <= end ; i++)
{
printf("%c",ch[i]);
}
}
int is_char(char c)
{
int i = 0;
if ((c >= 'a' && c <='z') ||(c >= 'A' && c <= 'Z'))
{
i = 1;
}
return i;
}
|