fork(1) download
  1. using System.Reflection;
  2. using System.Text.RegularExpressions;
  3. class P
  4. {
  5. static void r(string p)
  6. {
  7. var s = Regex.Replace(p, @"program.*", @"
  8. using System;
  9. class t {
  10. static void readln(ref int v) {
  11. v = int.Parse(Console.ReadLine());
  12. }
  13. static void writeln(int v) {
  14. Console.WriteLine(v);
  15. }
  16. ");
  17. s = Regex.Replace(s, @"var (.*):.*", m => m.Result("static int $1;"));
  18. s = Regex.Replace(s, @"readln\((\w+)\)", "readln(ref $1)");
  19. s = s.Replace("begin", "static void Main() {").Replace("end.", "}}").Replace(":=", "=");
  20. object o = new Microsoft.CSharp.CSharpCodeProvider()
  21. .CompileAssemblyFromSource(new System.CodeDom.Compiler.CompilerParameters(), s)
  22. .CompiledAssembly.CreateInstance("t");
  23. o.GetType().GetMethod("Main", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, null);
  24. }
  25.  
  26. static void Main()
  27. {
  28. r(@"
  29. program test;
  30. var a, b, c: integer;
  31. begin
  32. readln(a);
  33. readln(b);
  34. c := a + b;
  35. writeln(c);
  36. end.
  37. ");
  38. r(@"
  39. program MyProgram;
  40. var a, b, c, d: integer;
  41. begin
  42. readln(a);
  43. readln(b);
  44. readln(d);
  45. c := (a + b) / d;
  46. writeln(c);
  47. end.
  48. ");
  49. }
  50. }
  51.  
Success #stdin #stdout 1.67s 37728KB
stdin
44
44
100
100
2
stdout
88
100