博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 1566 Haiku Review
阅读量:4982 次
发布时间:2019-06-12

本文共 4556 字,大约阅读时间需要 15 分钟。

Haiku Review

Time Limit: 1000MS

Memory Limit: 10000K

Total Submissions: 647

Accepted: 393

Description

Haiku is an ancient form of Japanese poetry. A haiku is a three-line poem with seventeen syllables, where the first line must contain five syllables, the second line must contain seven syllables, and the third line must contain five syllables. The lines do not have to rhyme. Here is an example, where slashes separate the lines:

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 indigestioncomputer programs/the bugs try to eat my code/i will not let thema e i o u/this is seven syllables/a e i o u ye/o/i

Sample Output

Y23
1: #include
2: using namespace std;
3: char sentense[210];
4: int main()
5: {
6: 	int line1,line2,line3;
7: //	freopen("E:\\c++\\oj\\t.txt","rt",stdin);
8: 	while(1)
9: 	{
10: 		memset(sentense,'\0',sizeof(char)*210);
11: 		cin.getline(sentense,210,'\n');
12: 		if(strcmp(sentense,"e/o/i")==0)
13: 			break;
14: 		line3=strlen(sentense);
15: 		for(int i=0;i
16: 		{
17: 			if(sentense[i]=='/')
18: 			{
19: 				line1=i;
20: 				break;
21: 			}
22: 		}
23: 		for(int i=line1+1;i
24: 		{
25: 			if(sentense[i]=='/')
26: 			{
27: 				line2=i;
28: 				break;
29: 			}
30: 		}
31: 		int count1=0;
32: 		int vo_flag=0;
33: 		for(int i=0;i
34: 		{
35: 			if(sentense[i]=='a'||sentense[i]=='e'||
36: 				sentense[i]=='i'||sentense[i]=='o'||
37: 				sentense[i]=='u'||sentense[i]=='y')
38: 			{
39: 				if(vo_flag==0)
40: 				{
41: 					count1++;
42: 					vo_flag=1;
43: 				}
44: 			}
45: 			else
46: 			{
47: 				vo_flag=0;
48: 			}
49: 		}
50: 		if(count1!=5)
51: 		{
52: 			cout<<"1"<
53: 			continue;
54: 		}
55: 		int count2=0;
56: 		int vo_flag2=0;
57: 		for(int i=line1;i
58: 		{
59: 			if(sentense[i]=='a'||sentense[i]=='e'||
60: 				sentense[i]=='i'||sentense[i]=='o'||
61: 				sentense[i]=='u'||sentense[i]=='y')
62: 			{
63: 				if(vo_flag2==0)
64: 				{
65: 					count2++;
66: 					vo_flag2=1;
67: 				}
68: 			}
69: 			else
70: 			{
71: 				vo_flag2=0;
72: 			}
73: 		}
74: 		if(count2!=7)
75: 		{
76: 			cout<<"2"<
77: 			continue;
78: 		}
79: 		int count3=0;
80: 		int vo_flag3=0;
81: 		for(int i=line2;i
82: 		{
83: 			if(sentense[i]=='a'||sentense[i]=='e'||
84: 				sentense[i]=='i'||sentense[i]=='o'||
85: 				sentense[i]=='u'||sentense[i]=='y')
86: 			{
87: 				if(vo_flag3==0)
88: 				{
89: 					count3++;
90: 					vo_flag3=1;
91: 				}
92: 			}
93: 			else
94: 			{
95: 				vo_flag3=0;
96: 			}
97: 		}
98: 		if(count3!=5)
99: 		{
100: 			cout<<"3"<
101: 			continue;
102: 		}
103: 		cout<<"Y"<
104: 	}
105: 	return 0;
106: }
107:
108:

转载于:https://www.cnblogs.com/w0w0/archive/2011/11/21/2257650.html

你可能感兴趣的文章