Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _14._Slogan
- {
- class Program
- {
- static HashSet<string> collection = new HashSet<string>();
- static void Main(string[] args)
- {
- var n = int.Parse(Console.ReadLine());
- if (n<1 || n > 10)
- {
- throw new ArgumentOutOfRangeException("N must be a valid integer between the following range 1 <= N <= 10.");
- }
- for (int i = 0; i < n; i++)
- {
- var words = Console.ReadLine().Split(' ').ToArray();
- var slogan = Console.ReadLine();
- if (!isValid(words, slogan, string.Empty))
- {
- Console.WriteLine("NOT VALID");
- }
- }
- }
- static bool isValid (string[] words, string slogan, string output )
- {
- if (slogan.Length <= 0)
- {
- Console.WriteLine(output);
- return true;
- }
- if (!collection.Add(slogan))
- {
- return false;
- }
- foreach (var item in words)
- {
- if (slogan.StartsWith(item))
- {
- if (isValid(words,slogan.Substring(item.Length), output + item + " "))
- {
- return true;
- }
- else
- {
- collection.Add(slogan);
- }
- }
- }
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment