Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. <?php
  2. $CC="g++";
  3. $out="timeout 5s ./a.out";
  4. $code=$_POST["code"];
  5. $input=$_POST["input"];
  6. $filename_code="main.cpp";
  7. $filename_in="input.txt";
  8. $filename_error="error.txt";
  9. $executable="a.out";
  10. $command=$CC." -lm ".$filename_code;
  11. $command_error=$command." 2>".$filename_error;
  12. $check=0;
  13.  
  14. //if(trim($code)=="")
  15. //die("The code area is empty");
  16.  
  17. $file_code=fopen($filename_code,"w+");
  18. fwrite($file_code,$code);
  19. fclose($file_code);
  20. $file_in=fopen($filename_in,"w+");
  21. fwrite($file_in,$input);
  22. fclose($file_in);
  23. exec("chmod -R 777 $filename_in");
  24. exec("chmod -R 777 $filename_code");
  25. exec("chmod 777 $filename_error");
  26.  
  27. shell_exec($command_error);
  28. exec("chmod -R 777 $executable");
  29. $error=file_get_contents($filename_error);
  30. $executionStartTime = microtime(true);
  31.  
  32. if(trim($error)=="")
  33. {
  34. if(trim($input)=="")
  35. {
  36. $output=shell_exec($out);
  37. }
  38. else
  39. {
  40. $out=$out." < ".$filename_in;
  41. $output=shell_exec($out);
  42.  
  43. }
  44. //echo "<pre>$output</pre>";
  45. echo "<textarea id='div' class="form-control" name="output" rows="10" cols="50">$output</textarea><br><br>";
  46. }
  47. else if(!strpos($error,"error"))
  48. {
  49. echo "<pre>$error</pre>";
  50. if(trim($input)=="")
  51. {
  52. $output=shell_exec($out);
  53. }
  54. else
  55. {
  56. $out=$out." < ".$filename_in;
  57. $output=shell_exec($out);
  58. }
  59. echo "<textarea id='div' class="form-control" name="output" rows="10" cols="50">$output</textarea><br><br>";
  60. }
  61. else
  62. {
  63. echo "<pre>$error</pre>";
  64. $check=1;
  65. }
  66. $executionEndTime = microtime(true);
  67. $seconds = $executionEndTime - $executionStartTime;
  68. $seconds = sprintf('%0.2f', $seconds);
  69. echo "<pre>Compiled And Executed In: $seconds s</pre>";
  70.  
  71.  
  72. if($check==1)
  73. {
  74. echo "<pre>Verdict : CE</pre>";
  75. }
  76. else if($check==0 && $seconds>3)
  77. {
  78. echo "<pre>Verdict : TLE</pre>";
  79. }
  80. else if(trim($output)=="")
  81. {
  82. echo "<pre>Verdict : WA</pre>";
  83. }
  84. else if($check==0)
  85. {
  86. echo "<pre>Verdict : AC</pre>";
  87. }
  88.  
  89. exec("rm $filename_code");
  90. exec("rm *.o");
  91. exec("rm *.txt");
  92. exec("rm $executable");
  93. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement