Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices.ComTypes;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7. using System.Threading.Tasks;
  8.  
  9.  
  10. class TextTransformer
  11. {
  12. static void Main()
  13. {
  14. StringBuilder text = new StringBuilder();
  15. string input = Console.ReadLine();
  16. while (input != "burp")
  17. {
  18. text.Append(input);
  19. input = Console.ReadLine();
  20. }
  21.  
  22. string result = Regex.Replace(text.ToString(), @"\s{2,}", " ");
  23.  
  24. string pattern = @"([$&%'])([^$&%']+)\1";
  25. Regex regSeparate = new Regex(pattern);
  26. MatchCollection matches = regSeparate.Matches(result);
  27.  
  28. var outputText = new List<char>();
  29. bool isEven = true;
  30. int argumnet = 0;
  31. foreach (Match match in matches)
  32. {
  33. isEven = true;
  34. string output = match.Groups[2].Value;
  35. string specSymbol = match.Groups[1].Value;
  36.  
  37. char[] arr = output.ToCharArray();
  38. switch (specSymbol)
  39. {
  40. case "$":
  41. argumnet = 1;
  42. break;
  43. case "%":
  44. argumnet = 2;
  45. break;
  46. case "&":
  47. argumnet = 3;
  48. break;
  49. case "'":
  50. argumnet = 4;
  51. break;
  52. }
  53.  
  54. for (int i = 0; i < arr.Length; i++)
  55. {
  56. if (isEven)
  57. {
  58. int symb = arr[i] + argumnet;
  59. outputText.Add(((char)(symb)));
  60.  
  61. isEven = false;
  62. }
  63. else
  64. {
  65. int symb = arr[i] - argumnet;
  66. outputText.Add(((char)(symb)));
  67. isEven = true;
  68. }
  69. }
  70. }
  71. Console.WriteLine(string.Join("", outputText));
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement