coderforces B. Verse Pattern 字符处理

本文介绍了一种用于验证给定文本是否符合特定韵律模式的算法。该算法通过分析每行文本中的单词,并将包含元音字母的单词进一步划分为音节来实现。最终判断整个文本的音节数是否与预设的韵律模式相匹配。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

B. Verse Pattern
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a text consisting of n lines. Each line contains some space-separated words, consisting of lowercase English letters.

We define a syllable as a string that contains exactly one vowel any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowels: 'a', 'e', 'i', 'o', 'u' and 'y'.

Each word of the text that contains at least one vowel can be divided into syllables. Each character should be a part of exactly one syllable. For example, the word "mamma" can be divided into syllables as "ma" and "mma", "mam" and "ma", and "mamm" and "a". Words that consist of only consonants should be ignored.

The verse patterns for the given text is a sequence of n integers p1, p2, ..., pn. Text matches the given verse pattern if for each i from 1 ton one can divide words of the i-th line in syllables in such a way that the total number of syllables is equal to pi.

You are given the text and the verse pattern. Check, if the given text matches the given verse pattern.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of lines in the text.

The second line contains integers p1, ..., pn (0 ≤ pi ≤ 100) — the verse pattern.

Next n lines contain the text itself. Text consists of lowercase English letters and spaces. It's guaranteed that all lines are non-empty, each line starts and ends with a letter and words are separated by exactly one space. The length of each line doesn't exceed 100 characters.

Output

If the given text matches the given verse pattern, then print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes).

Examples
input
3
2 2 3
intel
code
ch allenge
output
YES
input
4
1 2 3 1
a
bcdefghi
jklmnopqrstu
vwxyz
output
NO
input
4
13 11 15 15
to be or not to be that is the question
whether tis nobler in the mind to suffer
the slings and arrows of outrageous fortune
or to take arms against a sea of troubles
output
YES
Note

In the first sample, one can split words into syllables in the following way:

in-tel
co-de
ch al-len-ge

Since the word "ch" in the third line doesn't contain vowels, we can ignore it. As the result we get 2 syllabels in first two lines and 3syllables in the third one.

统计元音字符个数

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 2009
#define INF 9999999999999
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=5e2+10;
using namespace std;
typedef  long long ll;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
ll my_min(ll x,ll y){ return x>y?y:x;};

int main()
{
	int n;
	char t[1005];
	int a[105];
	char str[105][1005];
	char word[105][105];
	while(gets(t)!=NULL)
	{

		n=0;
		for(int j=strlen(t)-1;j>=0;j--)
		{
			n += ((int)pow(10,j))*(t[strlen(t)-j-1]-'0'); 
		}
		int flag ; 
		int i,t1=0;
		int num,num1;
		int wordnum=0;
		int wordlen=0;
		memset(a,0,sizeof(a));
		memset(str,0,sizeof(str));
		memset(word,0,sizeof(word));
		gets(t);
		for(int j=0;j<=strlen(t);j++)
		{
			if(t[j]==' '||t[j]=='\0')
			{
				wordnum++;
				wordlen = '\0';
				wordlen=0;
				j++;
			}
			word[wordnum][wordlen++] = t[j];
		}
		
		for(i=0;i<wordnum;i++)
		{
			//puts(word[i]);
			int temp=0;
			for(int j=strlen(word[i])-1;j>=0;j--)
			{
				temp += ((int)pow(10,j))*(word[i][strlen(word[i])-j-1]-'0'); 
			}
			a[i] = temp;
		}	
		for(i=1;i<=n;i++)
		{
			gets(str[i]);
		}
			
			
		for(i=1;i<=n;i++)
		{
			int k=0;
			int re = 0;
			int re1= 0;
			wordnum=0;
			wordlen=0;
			int len = strlen(str[i]);
			memset(word,0,sizeof(word));
			for(int j=0;j<=len;j++)
			{
				if(str[i][j]==' '||str[i][j]=='\0')
				{
					wordnum++;
					wordlen = '\0';
					wordlen=0;
					j++;
				}
				word[wordnum][wordlen++] = str[i][j];
			}
			
			for(int j=0;j<wordnum;j++)
			{
				for(int k=0;k<strlen(word[j]);k++)
				{
					if(word[j][k]=='a'||word[j][k]=='e'||
					word[j][k]=='i'||word[j][k]=='o'||word[j][k]=='u'||word[j][k]=='y')
					re++;
				}
			}
			if(re != a[i-1])
				break;
		}
		
		if(i==n+1)
			printf("YES\n");
		else
			printf("NO\n");
	}
    return 0;
}







Exception setting up node for Apparel_Pants on Robert: System.ArgumentException: Illegal characters in path. [Ref 67275643] Duplicate stacktrace, see ref for original UnityEngine.StackTraceUtility:ExtractStackTrace () (wrapper dynamic-method) MonoMod.Utils.DynamicMethodDefinition:Verse.Log.Error_Patch3 (string) (wrapper dynamic-method) MonoMod.Utils.DynamicMethodDefinition:Verse.PawnRenderTree.SetupApparelNodes_Patch0 (Verse.PawnRenderTree) (wrapper dynamic-method) MonoMod.Utils.DynamicMethodDefinition:Verse.PawnRenderTree.SetupDynamicNodes_Patch1 (Verse.PawnRenderTree) (wrapper dynamic-method) MonoMod.Utils.DynamicMethodDefinition:Verse.PawnRenderTree.TrySetupGraphIfNeeded_Patch1 (Verse.PawnRenderTree) (wrapper dynamic-method) MonoMod.Utils.DynamicMethodDefinition:Verse.PawnRenderTree.EnsureInitialized_Patch1 (Verse.PawnRenderTree,Verse.PawnRenderFlags) (wrapper dynamic-method) MonoMod.Utils.DynamicMethodDefinition:Verse.PawnRenderer.RenderCache_Patch0 (Verse.PawnRenderer,Verse.Rot4,single,UnityEngine.Vector3,bool,bool,bool,bool,System.Collections.Generic.IReadOnlyDictionary`2<RimWorld.Apparel, UnityEngine.Color>,System.Nullable`1<UnityEngine.Color>,bool) RimWorld.PawnCacheRenderer:OnPostRender () (wrapper dynamic-method) MonoMod.Utils.DynamicMethodDefinition:RimWorld.PawnCacheRenderer.RenderPawn_Patch1 (RimWorld.PawnCacheRenderer,Verse.Pawn,UnityEngine.RenderTexture,UnityEngine.Vector3,single,single,Verse.Rot4,bool,bool,bool,bool,UnityEngine.Vector3,System.Collections.Generic.IReadOnlyDictionary`2<RimWorld.Apparel, UnityEngine.Color>,System.Nullable`1<UnityEngine.Color>,bool) RimWorld.PortraitsCache/PortraitParams:RenderPortrait (Verse.Pawn,UnityEngine.RenderTexture) RimWorld.PortraitsCache:Get (Verse.Pawn,UnityEngine.Vector2,Verse.Rot4,UnityEngine.Vector3,single,bool,bool,bool,bool,System.Collections.Generic.IReadOnlyDictionary`2<RimWorld.Apparel, UnityEngine.Color>,System.Nullable`1<UnityEngine.Color>,bool,System.Nullable`1<Verse.PawnHealthState>) (wrapper dynamic-method) MonoMod.Utils.DynamicMethodDefinition:RimWorld.ColonistBarColonistDrawer.DrawColonist_Patch1 (RimWorld.ColonistBarColonistDrawer,UnityEngine.Rect,Verse.Pawn,Verse.Map,bool,bool) RimWorld.ColonistBar:ColonistBarOnGUI () (wrapper dynamic-method) MonoMod.Utils.DynamicMethodDefinition:RimWorld.MapInterface.MapInterfaceOnGUI_BeforeMainTabs_Patch1 (RimWorld.MapInterface) (wrapper dynamic-method) MonoMod.Utils.DynamicMethodDefinition:RimWorld.UIRoot_Play.UIRootOnGUI_Patch3 (RimWorld.UIRoot_Play) (wrapper dynamic-method) MonoMod.Utils.DynamicMethodDefinition:Verse.Root.OnGUI_Patch2 (Verse.Root)
最新发布
03-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值