跳到正文

题解

题解:UVA576 Haiku Review

wanganze约 1 分钟
原文
文章信息与版本

文章信息

收录
2026年1月3日
更新
2026年1月3日
篇幅
约 1 分钟
题目
UVA576

版本

  1. v1当前

题意

给你三个由 / 分开的句子,问你音节个数(元音的段数)是否符合要求(元音包括 aeiouy)。

分享

要想将这题代码写简短,重点在于读入。

首先,getline() 函数支持读取终止符,本题就是 /,用 stringstream 来提供输入流。

然后判断元音可以用 find(),对每段的首个元音计数即可。

实现

C++
#include<bits/stdc++.h>
using namespace std;
string s,a[4],m = "aeiouy";
int cnt[4],res;
int main()
{
	while(getline(cin,s),s != "e/o/i")
	{
		memset(cnt,0,sizeof cnt);
		stringstream sin;
		sin<<s;
		res = 0;
		for(int i = 1; i <= 3; i ++) getline(sin,a[i],'/');
		for(int i = 1; i <= 3; i ++)
			for(int j = 0; j < a[i].size(); j ++)
				if(~m.find(a[i][j]) && (!j || m.find(a[i][j - 1]) == -1)) cnt[i] ++;
		if(cnt[1] != 5) puts("1");
		else if(cnt[2] != 7) puts("2");
		else if(cnt[3] != 5) puts("3");
		else puts("Y");
	}
	return 0;
}
原文