QM9A editorial

PROBLEM LINK:

Practice

Contest

Author: Chandan Boruah

Tester: Chandan Boruah

Editorialist: Chandan Boruah

DIFFICULTY:

EASY

PREREQUISITES:

Basic programming.

PROBLEM:

Given few strings, find how many of them rhyme to each other. Two strings rhyme if the last vowel is the same.

QUICK EXPLANATION:

Compare each string to each other and then find the last vowel in each and find if they rhyme.

EXPLANATION:

A nested for loop by which you compare one string to the other, iterate from the last letter of each string to find the first vowel, if they are same in any case increment counter.

Solution in CS:

using System;
class some
{
	public static void Main()
	{
		int n=int.Parse(Console.ReadLine());
		while((n--)>0)
		{
			Console.ReadLine();
			string []words=Console.ReadLine().Split();
			int count=0;
			for(int i=0;i<words.Length;i++)
			{
				for(int j=i+1;j<words.Length;j++)
				{
					string a=words[i];
					string b=words[j];
					if(yes(a,b))count+=2;
				}
			}Console.WriteLine(count);
		}
	}
	public static bool yes(string a, string b)
	{
		int inda=0-1;
		for(int j=a.Length-1;j>=0;j--)
		{
			if(Array.IndexOf("aeiou".ToCharArray(),a[j])>=0)
			{
				inda=j;break;
			}
		}int indb=0-1;
		for(int j=b.Length-1;j>=0;j--)
		{
			if(Array.IndexOf("aeiou".ToCharArray(),b[j])>=0)
			{
				indb=j;break;
			}
		}
		if(inda<0 || indb<0)return false;
		if(a[inda]==b[indb])return true;
		return false;
	}
}