ZOJ-1713

来源:互联网 发布:复制门禁卡软件 编辑:程序博客网 时间:2024/06/06 03:13

其实那段计算syllables的代码应该抽取成一个函数的,看见重复代码总不太爽,不过由于太简单了就懒的搞了。。直接copy

#include<stdio.h>#include<string.h>int isSyllable(char c){    return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y';}int main(){    char s[200];    while (gets(s), strcmp(s, "e/o/i"))    {        int i, first = 0, second = 0, third = 0;        int flag = 0;        for (i = 0; s[i] != '/'; i++)        {            if (isSyllable(s[i]) && !flag)            {                first++;                flag = 1;            }            else if (isSyllable(s[i]))                flag = 1;            else                flag = 0;        }        flag = 0;        for (i += 1; s[i] != '/'; i++)        {            if (isSyllable(s[i]) && !flag)            {                second++;                flag = 1;            }            else if (isSyllable(s[i]))                flag = 1;            else                flag = 0;        }        flag = 0;        for (i += 1; s[i] != '\0'; i++)        {            if (isSyllable(s[i]) && !flag)            {                third++;                flag = 1;            }            else if (isSyllable(s[i]))                flag = 1;            else                flag = 0;        }        if (first != 5)            printf("1\n");        else if (second != 7)            printf("2\n");        else if (third != 5)            printf("3\n");        else            printf("Y\n");    }    return 0;}



0 0
原创粉丝点击