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;
- namespace Tests
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- string pattern = @"<(?<tag>.*?)>(?<text>[^<]*?)</\k<tag>>";
- string lines = string.Empty;
- for (int count = 0; count < n; count++) lines += "\n" + Console.ReadLine();
- Match match = Regex.Match(lines, pattern);
- while (match.Success)
- {
- lines = lines.Replace(match.Value, Change(match.Groups["tag"].Value, match.Groups["text"].Value));
- match = Regex.Match(lines, pattern);
- }
- 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