Advertisement
LardaX

Cubic-Messages-WRONG!

Oct 20th, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Cubic_Messages
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. string pattern = @"(^\d+)([a-zA-Z]+)(\d*)\b";
  15. Regex regex = new Regex(pattern);
  16.  
  17.  
  18. string input = Console.ReadLine();
  19.  
  20. while (!input.Equals("Over!"))
  21. {
  22. int charLength = int.Parse(Console.ReadLine());
  23. Match match = regex.Match(input);
  24. StringBuilder sb = new StringBuilder();
  25. string firstGroup = match.Groups[1].ToString();
  26. string secondGroup = match.Groups[2].ToString();
  27. string thirdGroup = match.Groups[3].ToString();
  28.  
  29. if (secondGroup.Length.Equals(charLength))
  30. {
  31.  
  32. for (int i = 0; i < match.Groups[1].Length; i++)
  33. {
  34.  
  35. int index = int.Parse(firstGroup[i].ToString());
  36. if (index < secondGroup.Length)
  37. {
  38. sb.Append(secondGroup[index]);
  39. }
  40. else
  41. {
  42. sb.Append(" ");
  43. }
  44. }
  45.  
  46. for (int i = 0; i < thirdGroup.Length; i++)
  47. {
  48. int index = int.Parse(thirdGroup[i].ToString());
  49. if (index < secondGroup.Length)
  50. {
  51. sb.Append(secondGroup[index]);
  52. }
  53. else
  54. {
  55. sb.Append(" ");
  56. }
  57. }
  58.  
  59. Console.WriteLine($"{match.Groups[2]} == {sb}");
  60. }
  61.  
  62. input = Console.ReadLine();
  63. }
  64.  
  65.  
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement