Advertisement
Guest User

Untitled

a guest
May 27th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1.  
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace _10._1
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string expr = "m (9, p (p (3, 5), m (3, 8)))";
  14. expr = Regex.Replace(expr, @"\s+", "");
  15. Regex m = new Regex(@"m\((-?\d+),(-?\d+)\)");
  16. Regex p = new Regex(@"p\((-?\d+),(-?\d+)\)");
  17. while (m.IsMatch(expr) || p.IsMatch(expr))
  18. {
  19. expr = m.Replace(expr, (Match m1) => ((int.Parse(m1.Groups[1].Value) - int.Parse(m1.Groups[2].Value)) % 10).ToString());
  20. expr = p.Replace(expr, (Match m1) => ((int.Parse(m1.Groups[1].Value) + int.Parse(m1.Groups[2].Value)) % 10).ToString());
  21. }
  22. Console.WriteLine(expr);
  23. }
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement