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.RegularExpressions;
- class FakeMarkup
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- string pattern = "<(.*?)>";
- string lines = string.Empty;
- for (int count = 0; count < n; count++) lines += "\n" + Console.ReadLine();
- Match prev = Regex.Match(lines, pattern);
- while (prev.Success)
- {
- Match next = prev.NextMatch();
- if (next.Groups[1].Value == ("/" + prev.Groups[1].Value))
- {
- string original = lines.Substring(prev.Index, next.Index + next.Length - prev.Index);
- int start = prev.Index + prev.Length;
- int end = next.Index - start;
- string affected = lines.Substring(start, end);
- lines = lines.Replace(original, Change(prev.Value, affected));
- prev = Regex.Match(lines, pattern);
- }
- else prev = next;
- }
- Console.WriteLine(lines);
- }
- static string Change(string action, string text)
- {
- switch (action)
- {
- case "<upper>":
- {
- return text.ToUpper();
- }
- case "<lower>":
- {
- return text.ToLower();
- }
- case "<toggle>":
- {
- char[] result = text.ToCharArray();
- for (int i = 0; i < result.Length; i++)
- {
- if (char.IsLower(result[i])) result[i] = char.ToUpper(result[i]);
- else if (char.IsUpper(result[i])) result[i] = char.ToLower(result[i]);
- }
- return (new string(result));
- }
- case "<rev>":
- {
- return new string(text.Reverse().ToArray());
- }
- }
- return string.Empty;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement