fork(1) download
  1. using System;
  2. using Microsoft.CSharp;
  3. using System.Collections.Generic;
  4. using System.CodeDom.Compiler;
  5. using System.Diagnostics;
  6.  
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string sourceCode = "class e{static void Main(){System.Console.Write(new char[1\n#if l\n#else\n*5]{'w','o','r','l','d'\n#if o\n#else\n});\n#endif\n}\n#endif\n}";
  12.  
  13. Console.WriteLine(isPristine(sourceCode) ? "Pristine" : "Not pristine");
  14. Console.ReadLine();
  15. }
  16.  
  17. static bool isPristine(string sourceCode)
  18. {
  19. using (var csc = new CSharpCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", "v3.5" } }))
  20. {
  21. var parameters = new CompilerParameters(new[] { "mscorlib.dll", "System.Core.dll" });
  22.  
  23. int length = sourceCode.Length;
  24. List<string> substringsThatWork = new List<string>();
  25.  
  26. for (int i = 0; i < length; i++)
  27. {
  28. for (int j = 1; j < length - i; j++)
  29. {
  30. string sourceWithRemoval = sourceCode.Remove(i, j);
  31. CompilerResults results = csc.CompileAssemblyFromSource(parameters, sourceWithRemoval);
  32.  
  33. if (results.Errors.Count == 0)
  34. {
  35. Debug.WriteLine("Still works by removing:");
  36. Debug.WriteLine("@{0}@ ", sourceWithRemoval);
  37. Debug.WriteLine("At index {0}.", i);
  38.  
  39. return false;
  40. }
  41. }
  42. }
  43. }
  44.  
  45. return true;
  46. }
  47. }
Time limit exceeded #stdin #stdout 5s 36600KB
stdin
Standard input is empty
stdout
Standard output is empty