Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace Text_Transformer
- {
- class Program
- {
- public static int getWeight(string ch)
- {
- int weight = 0;
- switch (ch)
- {
- case "$":
- weight = 1;
- break;
- case "%":
- weight = 2;
- break;
- case "&":
- weight = 3;
- break;
- case "\'":
- weight = 4;
- break;
- }
- return weight;
- }
- static void Main(string[] args)
- {
- StringBuilder sb = new StringBuilder();
- while (true)
- {
- string input = Console.ReadLine();
- if (input.Equals("burp"))
- {
- break;
- }
- sb.Append(input);
- }
- string gibberishStr = sb.ToString();
- gibberishStr = Regex.Replace(gibberishStr, @"\s+", " ");
- string pattern = @"([$%&'])([^$%&']+)\1";
- Regex textBetweenSpecialChars = new Regex(pattern);
- MatchCollection matchCollection = Regex.Matches(gibberishStr, pattern);
- List<string> words = new List<string>();
- List<string> specialSymbols = new List<string>();
- for (int i = 0; i < matchCollection.Count; i++)
- {
- var match = matchCollection[i].Groups[2].ToString();
- words.Add(match);
- specialSymbols.Add(matchCollection[i].Groups[1].ToString());
- }
- List<string> resultWords = new List<string>();
- for (int i = 0; i < words.Count; i++)
- {
- var chars = words[i].ToCharArray();
- var specialSymbol = specialSymbols[i];
- StringBuilder word = new StringBuilder();
- for (int j = 0; j < chars.Length; j++)
- {
- char ch = chars[j];
- char transformedChar = Char.MinValue;
- if (j%2 == 0)
- {
- transformedChar = (char) (ch + getWeight(specialSymbol));
- }
- else
- {
- transformedChar = (char) (ch - getWeight(specialSymbol));
- }
- word.Append(transformedChar);
- }
- resultWords.Add(word.ToString());
- }
- Console.WriteLine(String.Join(" ", resultWords));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement