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 _10._1
- {
- class Program
- {
- static void Main(string[] args)
- {
- string expr = "m (9, p (p (3, 5), m (3, 8)))";
- expr = Regex.Replace(expr, @"\s+", "");
- Regex m = new Regex(@"m\((-?\d+),(-?\d+)\)");
- Regex p = new Regex(@"p\((-?\d+),(-?\d+)\)");
- while (m.IsMatch(expr) || p.IsMatch(expr))
- {
- expr = m.Replace(expr, (Match m1) => ((int.Parse(m1.Groups[1].Value) - int.Parse(m1.Groups[2].Value)) % 10).ToString());
- expr = p.Replace(expr, (Match m1) => ((int.Parse(m1.Groups[1].Value) + int.Parse(m1.Groups[2].Value)) % 10).ToString());
- }
- Console.WriteLine(expr);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement