Advertisement
Guest User

Untitled

a guest
May 14th, 2017
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. public class JediCodeX
  7. {
  8.     public static void Main()
  9.     {
  10.         int n = int.Parse(Console.ReadLine());
  11.         string input = string.Empty;
  12.         List<string> encodedText = new List<string>();
  13.         List<string> jedis = new List<string>();
  14.         List<string> messages = new List<string>();
  15.  
  16.         for (int i = 0; i < n; i++)
  17.         {
  18.             input = Console.ReadLine();
  19.             encodedText.Add(input);
  20.         }
  21.  
  22.         string firstPattern = Console.ReadLine();
  23.         string secondPattern = Console.ReadLine();
  24.         int[] indexes = Console.ReadLine().Split().Select(int.Parse).ToArray();
  25.  
  26.         for (int i = 0; i < encodedText.Count; i++)
  27.         {
  28.             Match matchName = Regex.Match(encodedText[i], @"(" + firstPattern + ")([a-zA-Z]{" + firstPattern.Length + "})(?![a-zA-Z])");
  29.             Match matchMessage = Regex.Match(encodedText[i], @"(" + secondPattern + @")([a-zA-Z\d]{" + secondPattern.Length + @"})(?![a-zA-Z\d])");
  30.  
  31.             while (matchName.Success)
  32.             {
  33.                 jedis.Add(matchName.Groups[2].Value);
  34.                 matchName = matchName.NextMatch();
  35.             }
  36.             while (matchMessage.Success)
  37.             {
  38.                 messages.Add(matchMessage.Groups[2].Value);
  39.                 matchMessage = matchMessage.NextMatch();
  40.             }
  41.         }
  42.  
  43.         int index = 0;
  44.         foreach (var jedi in jedis)
  45.         {
  46.             for (int i = index; i < indexes.Length; i++)
  47.             {
  48.                 index++;
  49.                 if (messages.Count >= indexes[i])
  50.                 {
  51.                     Console.WriteLine($"{jedi} - {messages[indexes[i] - 1]}");
  52.                     break;
  53.                 }
  54.             }
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement