Time Limit: 2000MS | Memory Limit: 65536KB | 64bit IO Format: %lld & %llu |
Description
Computer programs/The bugs try to eat my code/I must not let them.
You must write a program that will review a haiku and check that each line contains the correct number of syllables.
Input
The input contains one or more lines, each of which contains a single haiku. A haiku will contain at least three words, and words will be separated by either a single space or a slash (`/'). Slashes also separate the three lines of a haiku, so each haiku will contain exactly two slashes. (The three lines of the haiku will be contained within one physical line of the file.) A haiku will contain only lowercase letters (`a'-`z'), forward slashes (`/'), and spaces, and will be no more than 200 characters long (not counting the end-of-line characters).
The haiku `e/o/i' signals the end of the input.
Each haiku is guaranteed to contain three lines, and each line will contain at least one word. Your job is to determine whether each line has the correct number of syllables (5/7/5). For the purposes of this problem, every contiguous sequence of one or more vowels counts as one syllable, where the vowels are a, e, i, o, u, and y. Every word will contain at least one syllable. (Note that this method of counting syllables does not always agree with English conventions. In the second example below, your program must consider the word `code' to have two syllables because the `o' and the `e' are not consecutive. However, in English the `e' is silent and so `code' actually has only one syllable.)
Output
For each haiku, output a single line that contains `1' if the first line has the wrong number of syllables, `2' if the second line has the wrong number of syllables, `3' if the third line has the wrong number of syllables, or `Y' if all three lines have the correct number of syllables. If the haiku is not correct, you must output the number of the first line that has the wrong number of syllables.
Sample Input
happy purple frog/eating bugs in the marshes/get indigestion
computer programs/the bugs try to eat my code/i will not let them
a e i o u/this is seven syllables/a e i o u y
e/o/i
Sample Output
Y
2
3
Source
#include <iostream>
#include<cstdio>
#include<string>
using namespace std;
bool isvowel(char c)
{
if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='y')
return true;
else return false;
}
int main()
{
string s;
int count,j,i;
int model[3]={5,7,5};
bool flag;
while(getline(cin,s)&&s!="e/o/i")//字符串的读入,用getline()。记住用法
{
count=0;
j=0;
//flag=false;
for(i=0;i<s.size();i++)
{
switch(s[i])
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'y':
{
if(i>=1&&!isvowel(s[i-1])||i==0)//判断是否是连续元音
{
count++;
}
}
break;//记得case-break一起用
case '/':
//case '\0'://'\n'???,大概getline(cin,s)不是以'\0'或'\n'作为结束符
{
if(count==model[j])
{
flag=true;
j++;
count=0;//count记得置0
}
else
{
flag=false;
goto xx;//直接跳转,方便
}
}
}
}
if(flag&&j==2&&count==model[j])//j==2&&count==model[j]是为了判断最后一句,因为没有'/'作为分隔符
printf("Y\n");
else xx: printf("%d\n",j+1);//xx要放在else后面
}
return 0;
}