SHARE
TWEET

Untitled

a guest May 14th, 2017 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top