定义当一个字符串只有元音字母(a,e,i,o,u,A,E,I,O,U)组成,
称为元音字符串,现给定一个字符串,请找出其中最长的元音字符串,
并返回其长度,如果找不到请返回0,
字符串中任意一个连续字符组成的子序列称为该字符串的子串
输入描述:
一个字符串其长度 0<length ,字符串仅由字符a-z或A-Z组成
输出描述:
一个整数,表示最长的元音字符子串的长度
示例1:
输入
asdbuiodevauufgh
输出
3
说明:
最长的元音字符子串为uio和auu长度都为3,因此输出3
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX_LEN 1000
// a,e,i,o,u,A,E,I,O,U
int IsYuanWord(char s)
{
int result;
switch (s) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
result = 1;
break;
default:
result = 0;
break;
}
return result;
}
int GetLen(char *s, int idx)
{
int i;
int count = 0;
for (i = idx; i < strlen(s); i++) {
if (IsYuanWord(s[i]) == 0) {
break;
}
count++;
}
return count;
}
void GetYuanStr(char *s)
{
int len = strlen(s);
int i, pos = 0;
int max = 0;
int count;
for (i = 0; i < len; i++) {
if (IsYuanWord(s[i]) == 1) {
count = GetLen(s, i);
if (max < count) {
max = count;
}
pos = i;
i = i + count;
}
}
printf("max=%d", max, pos);
}
int main()
{
char s[MAX_LEN] = {0};
gets(s);
GetYuanStr(s);
return 0;
}