Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Numerics;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace lab
  8. {
  9. public class lab
  10. {
  11. private static void Main()
  12. {
  13. var line = Console.ReadLine();
  14. while (line != "Over!")
  15. {
  16. var n = int.Parse(Console.ReadLine());
  17. var regex = new Regex("^(\\d+)([A-Za-z]{" + n + "})[^a-zA-Z]*?(\\d+)?$");
  18. var match = regex.Match(line);
  19. if (match.Success)
  20. {
  21. string text = match.Groups[2].ToString();
  22. var left = match.Groups[1].ToString().ToCharArray();
  23. var right = match.Groups[3].ToString().ToCharArray();
  24. Console.Write(match.Groups[2]);
  25. Console.Write(" == ");
  26. for (int i = 0; i < left.Length; i++)
  27. {
  28. if (int.Parse(left[i].ToString()) < text.Length)
  29. {
  30. Console.Write(text[int.Parse(left[i].ToString())]);
  31. }
  32. else
  33. {
  34. Console.Write(" ");
  35. }
  36. }
  37. if (right.Length > 0)
  38. {
  39. for (int i = 0; i < right.Length; i++)
  40. {
  41. if (char.IsDigit(right[i]))
  42. {
  43. if (int.Parse(right[i].ToString()) < text.Length)
  44. {
  45. Console.Write(text[int.Parse(right[i].ToString())]);
  46. }
  47. else
  48. {
  49. Console.Write(" ");
  50. }
  51. }
  52. }
  53. }
  54. Console.WriteLine();
  55. }
  56. line = Console.ReadLine();
  57. }
  58.  
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement