Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Slogan
  8. {
  9.     class Program
  10.     {
  11.         static int n;
  12.         static string[] words;
  13.         static string slogan;
  14.         static StringBuilder resultSb = new StringBuilder();
  15.         static StringBuilder tempSb = new StringBuilder();
  16.         static void Main()
  17.         {
  18.             n = int.Parse(Console.ReadLine());
  19.             for (int i = 0; i < n; i++)
  20.             {
  21.                 words = Console.ReadLine().Split();
  22.                 slogan = Console.ReadLine();
  23.                 string currentResult = slogan;
  24.                 foreach (string word in words)
  25.                 {
  26.                     int timesMet = 0;
  27.                     if (currentResult.StartsWith(word))
  28.                     {
  29.                         timesMet++;
  30.                     }
  31.                     if (currentResult.EndsWith(word) && currentResult.Length > word.Length)
  32.                     {
  33.                         timesMet++;
  34.                     }
  35.                     string[] splitResult = currentResult.Split(new string[] { word }, StringSplitOptions.RemoveEmptyEntries);
  36.                     if (splitResult.Length > 1)
  37.                     {
  38.                         timesMet += splitResult.Length - 1;
  39.                     }
  40.                     currentResult = string.Join("", splitResult);
  41.                     if (timesMet > 0)
  42.                     {
  43.                         tempSb.Append(String.Join(" ", Enumerable.Repeat(word, timesMet)));
  44.                         tempSb.Append(' ');
  45.                     }
  46.                 }
  47.                 if (currentResult.Length > 0)
  48.                 {
  49.                     resultSb.AppendLine("NOT VALID");
  50.                 }
  51.                 else
  52.                 {
  53.                     resultSb.AppendLine(tempSb.ToString());
  54.                 }
  55.                 tempSb.Clear();
  56.             }
  57.             Console.Write(resultSb);
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement