Jeús Gómez avatar Jeús Gómez committed 52c6843

source organization restructured.

Comments (0)

Files changed (6)

 *.o
 *.pyc
 grader
+.sconsign.dblite
Add a comment to this file

.sconsign.dblite

Binary file removed.

+install_dir = "/usr/local/bin"
+
+src_files = Split("main.cpp "
+                  "grader.cpp")
+
+inc_dir = "."
+
 env = Environment()
-env.Program(target="grader", source=["main.cpp"])
+grader = env.Program(target="grader", source=src_files, CPPPATH=inc_dir)
+env.Install(install_dir, grader)
+env.Alias("install", [install_dir])
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <math.h>
-#include <time.h>
-
-#include <vector>
-#include <string>
-#include <algorithm>
-#include <functional>
-
-#ifdef WIN32
-    #include <windows.h>
-#else
-    #include <pthread.h>
-    #include <sys/types.h>
-    #include <unistd.h>
-#endif
-
-#define KB 1024
-#define MB KB*KB
-#define GB MB*KB
-
-#ifdef WIN32
-    #define SEC 1000
-#else
-    #define SEC 1
-#endif
-
-#define NF -1
-#define AC 0
-#define PE 1
-#define WA 2
-#define JE 3
-#define TL 4
-
-using namespace std;
-
-class solution {
-public:
-    string execName;
-    vector<string> inputs;
-    vector<string> outputs;
-    
-    solution() {}
-    
-    /**
-    *   Return codes:
-    *      -1 : No File.
-    *       0 : Acepted.
-    *       1 : Printing Error.
-    *       2 : Wrong Answer.
-    *       3 : Judge Error
-	*		4 : Time Limit Exceeded
-    */
-    int compare_solution(string fto_comp, int outputN) {
-        FILE * fin = fopen(fto_comp.c_str(), "r");
-        if(fin == NULL) {
-            return NF;
-        }
-	#ifdef WIN32
-            FILE * fin2 = fopen(("test\\" + outputs[outputN]).c_str(), "r");
-	#else
-	    FILE * fin2 = fopen(("test/" + outputs[outputN]).c_str(), "r");
-	#endif
-        if(fin2 == NULL) return JE;
-        if(file_comp(fin, fin2, false))
-            return AC;
-        else {
-            FILE * fin = fopen(fto_comp.c_str(), "r");
-	    #ifdef WIN32
-                FILE * fin2 = fopen(("test\\" + outputs[outputN]).c_str(), "r");
-	    #else
-	        FILE * fin2 = fopen(("test/" + outputs[outputN]).c_str(), "r");
-	    #endif
-            if(file_comp(fin, fin2, true))
-                return PE;
-            else
-                return WA;
-        }
-    }
-    
-    void show_solution(string fto_comp, int outputN, FILE * report) {
-        FILE * fin = fopen(fto_comp.c_str(), "r");
-	#ifdef WIN32
-            FILE * fin2 = fopen(("test\\" + outputs[outputN]).c_str(), "r");
-	#else
-            FILE * fin2 = fopen(("test/" + outputs[outputN]).c_str(), "r");
-        #endif            
-        if(!fin)
-            fprintf(report, "Got: \n");
-        else {
-            string str1 = get_file(fin);
-            fprintf(report, "Got:\n %s\n", str1.c_str());
-        }
-        string str2 = get_file(fin2);        
-        fprintf(report, "Expected:\n %s\n", str2.c_str());
-    }
-
-private:
-    string get_file(FILE * fin) {
-        string result = "";
-        char aux;
-        while(fscanf(fin, "%c", &aux)!=EOF) {
-            result.push_back(aux);
-        }
-        return result;
-    }
-    
-    bool file_comp(FILE * fin1, FILE * fin2, bool blanks) {
-        if(fin1 == NULL || fin2 == NULL) return false;
-        char a, b;
-        bool flag1 = true, flag2 = true;
-        while(flag1 && flag2) {
-            do{
-                fscanf(fin1, "%c", &a)==EOF?flag1=false:0;
-            } while(flag1 && blanks && isspace(a));
-            do{
-                fscanf(fin2, "%c", &b)==EOF?flag2=false:0;
-            } while(flag2 && blanks && isspace(b));  
-            if(isspace(a) || isspace(b)) continue;
-            if(a!=b) return false;            
-        }
-        if(!flag1 && !flag2) return true;
-        else return false;
-    }
- 
-};
-
-FILE * config;
-vector<solution> sols;
-string outputName;
-int timeLimit;
-
-string get_command(string exec, string input) {
-    string command;
-    #ifdef WIN32
-        command = "start /B bin\\" + exec + ".exe < test\\" + input;
-    #else
-        command = "./bin/" + exec + " < test/" + input + " > salida.txt &";
-    #endif
-    return command;
-}
-
-bool kill_proc(string procName) {
-    string command;
-    #ifdef WIN32
-        command = "taskkill /IM " + procName + ".exe /F";
-        return !system(command.c_str());
-    #else
-        command = "pkill -9 " + procName;
-	    return !system(command.c_str());
+#include <grader.h>
+
+solution::solution(){}
+
+/**
+ *   Return codes:
+ *      -1 : No File.
+ *       0 : Acepted.
+ *       1 : Printing Error.
+ *       2 : Wrong Answer.
+ *       3 : Judge Error
+ *       4 : Time Limit Exceeded
+ */
+int solution::compare_solution(string fto_comp, int outputN) {
+        FILE * fin = fopen(fto_comp.c_str(), "r");
+        if(fin == NULL) {
+            return NF;
+        }
+	#ifdef WIN32
+            FILE * fin2 = fopen(("test\\" + outputs[outputN]).c_str(), "r");
+	#else
+	    FILE * fin2 = fopen(("test/" + outputs[outputN]).c_str(), "r");
+	#endif
+        if(fin2 == NULL) return JE;
+        if(file_comp(fin, fin2, false))
+            return AC;
+        else {
+            FILE * fin = fopen(fto_comp.c_str(), "r");
+	    #ifdef WIN32
+                FILE * fin2 = fopen(("test\\" + outputs[outputN]).c_str(), "r");
+	    #else
+	        FILE * fin2 = fopen(("test/" + outputs[outputN]).c_str(), "r");
+	    #endif
+            if(file_comp(fin, fin2, true))
+                return PE;
+            else
+                return WA;
+        }
+}
+    
+void solution::show_solution(string fto_comp, int outputN, FILE * report) {
+        FILE * fin = fopen(fto_comp.c_str(), "r");
+	#ifdef WIN32
+            FILE * fin2 = fopen(("test\\" + outputs[outputN]).c_str(), "r");
+	#else
+            FILE * fin2 = fopen(("test/" + outputs[outputN]).c_str(), "r");
+        #endif            
+        if(!fin)
+            fprintf(report, "Got: \n");
+        else {
+            string str1 = get_file(fin);
+            fprintf(report, "Got:\n %s\n", str1.c_str());
+        }
+        string str2 = get_file(fin2);        
+        fprintf(report, "Expected:\n %s\n", str2.c_str());
+}
+
+string solution::get_file(FILE * fin) {
+        string result = "";
+        char aux;
+        while(fscanf(fin, "%c", &aux)!=EOF) {
+            result.push_back(aux);
+        }
+        return result;
+}
+    
+bool solution::file_comp(FILE * fin1, FILE * fin2, bool blanks) {
+        if(fin1 == NULL || fin2 == NULL) return false;
+        char a, b;
+        bool flag1 = true, flag2 = true;
+        while(flag1 && flag2) {
+            do{
+                fscanf(fin1, "%c", &a)==EOF?flag1=false:0;
+            } while(flag1 && blanks && isspace(a));
+            do{
+                fscanf(fin2, "%c", &b)==EOF?flag2=false:0;
+            } while(flag2 && blanks && isspace(b));  
+            if(isspace(a) || isspace(b)) continue;
+            if(a!=b) return false;            
+        }
+        if(!flag1 && !flag2) return true;
+        else return false;
+}
+
+FILE * config;
+vector<solution> sols;
+string outputName;
+int timeLimit;
+
+string get_command(string exec, string input) {
+    string command;
+    #ifdef WIN32
+        command = "start /B bin\\" + exec + ".exe < test\\" + input;
+    #else
+        command = "./bin/" + exec + " < test/" + input + " > salida.txt &";
     #endif
-	return false;
-}
-
-void kill_time(int secs) {
-    #ifdef WIN32
-        Sleep(SEC*secs);
-    #else
-        sleep(SEC*secs);
-    #endif
-}
+    return command;
+}
+
+bool kill_proc(string procName) {
+    string command;
+    #ifdef WIN32
+        command = "taskkill /IM " + procName + ".exe /F";
+        return !system(command.c_str());
+    #else
+        command = "pkill -9 " + procName;
+	    return !system(command.c_str());
+    #endif
+	return false;
+}
+
+void kill_time(int secs) {
+    #ifdef WIN32
+        Sleep(SEC*secs);
+    #else
+        sleep(SEC*secs);
+    #endif
+}
 
 string get_erase_cmd(string outputName) {
 	string result;
 	#endif
 	return result;	
 }
-
-void test() {
+
+void test() {
     FILE * report = fopen("report.txt", "w");
-	FILE * fscore = fopen("score.txt", "w");
-    if(report == NULL) {
-        perror("Cannot open report file!");
-        exit(1);
-    }
+	FILE * fscore = fopen("score.txt", "w");
+    if(report == NULL) {
+        perror("Cannot open report file!");
+        exit(1);
+    }
     for(int i=0; i<sols.size(); ++i) {
 		system(get_erase_cmd(outputName).c_str());
-        string execName = sols[i].execName;
-        fprintf(report, "\n\nReport for %s problem:\n\n\n", execName.c_str());
-        int score = 0;
-        for(int j=0; j < sols[i].inputs.size(); ++j) {
-            string com = get_command(execName, sols[i].inputs[j]);
-            system(com.c_str());
+        string execName = sols[i].execName;
+        fprintf(report, "\n\nReport for %s problem:\n\n\n", execName.c_str());
+        int score = 0;
+        for(int j=0; j < sols[i].inputs.size(); ++j) {
+            string com = get_command(execName, sols[i].inputs[j]);
+            system(com.c_str());
             kill_time(timeLimit);
-			int result;
+			int result;
             if(kill_proc(execName)) 
 				result = TL;
-			else
-		        result = sols[i].compare_solution(outputName, j);
-		    if(result == AC)
-	            fprintf(report, "OK!\n"), score++;
-	        else if(result == PE)
-	            fprintf(report, "Format Error\n"), score++;
-	        else if(result == TL)
-	            fprintf(report, "Time Limit Exceeded\n");
-	        else if(result == WA) {
-	            fprintf(report, "Wrong Answer\n");
-	            sols[i].show_solution(outputName, j, report);
-	        } else if(result == JE)
-	            fprintf(report, "Judge Error!\n");
-        }
-        fprintf(report, "\n --- Score: %d / %d --- \n", score, sols[i].inputs.size());
-        fprintf(fscore, "NOTA=%d\n", score);
-    }
+			else
+		        result = sols[i].compare_solution(outputName, j);			fprintf(report, "Case %d: ", j+1);
+		    if(result == AC)
+	            fprintf(report, "OK!\n"), score++;
+	        else if(result == PE)
+	            fprintf(report, "Format Error\n"), score++;
+	        else if(result == TL)
+	            fprintf(report, "Time Limit Exceeded\n");
+	        else if(result == WA) {
+	            fprintf(report, "Wrong Answer\n");
+	            sols[i].show_solution(outputName, j, report);
+	        } else if(result == JE)
+	            fprintf(report, "Judge Error!\n");
+        }
+        fprintf(report, "\n --- Score: %d / %d --- \n", score, sols[i].inputs.size());
+        fprintf(fscore, "NOTA=%d\n", score);
+    }
     fclose(report);
-}
-
-void start_grader() {
-    if(config == NULL) {
-        perror("No file loaded!\n");
-        exit(1);
-    }
-    int N;
-    int M;
-    char buff[KB];
-    fscanf(config, "%d", &N);
-    sols = vector<solution>(N);
-    for(int i=0; i<N; ++i) {
-        fscanf(config, "%s", buff);
-        sols[i].execName = buff;
-    }
-    for(int i=0; i<N; ++i) {
-        fscanf(config, "%d", &M);
-        for(int j=0; j<M; ++j) {
-            fscanf(config, "%s", buff);
-            sols[i].inputs.push_back(string(buff));            
-        }
-        fscanf(config, "%d", &M);
-        for(int j=0; j<M; ++j) {
-            fscanf(config, "%s", buff);
-            sols[i].outputs.push_back(string(buff));            
-        }
-    }
-    fscanf(config, "%s", buff);
-    fscanf(config, "%d", &timeLimit);
-    outputName = buff;
-    test();
-}
-
-bool try_open(char * fname) {
-    return ((config = fopen(fname, "r")) != NULL);
-}
-
+}
+
+void start_grader() {
+    if(config == NULL) {
+        perror("No file loaded!\n");
+        exit(1);
+    }
+    int N;
+    int M;
+    char buff[KB];
+    fscanf(config, "%d", &N);
+    sols = vector<solution>(N);
+    for(int i=0; i<N; ++i) {
+        fscanf(config, "%s", buff);
+        sols[i].execName = buff;
+    }
+    for(int i=0; i<N; ++i) {
+        fscanf(config, "%d", &M);
+        for(int j=0; j<M; ++j) {
+            fscanf(config, "%s", buff);
+            sols[i].inputs.push_back(string(buff));            
+        }
+        fscanf(config, "%d", &M);
+        for(int j=0; j<M; ++j) {
+            fscanf(config, "%s", buff);
+            sols[i].outputs.push_back(string(buff));            
+        }
+    }
+    fscanf(config, "%s", buff);
+    fscanf(config, "%d", &timeLimit);
+    outputName = buff;
+    test();
+}
+
+bool try_open(char * fname) {
+    return ((config = fopen(fname, "r")) != NULL);
+}
+#ifndef __GRADER__
+#define __GRADER__
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <math.h>
+#include <time.h>
+
+#include <vector>
+#include <string>
+#include <algorithm>
+#include <functional>
+
+#ifdef WIN32
+    #include <windows.h>
+#else
+    #include <pthread.h>
+    #include <sys/types.h>
+    #include <unistd.h>
+#endif
+
+#define KB 1024
+#define MB KB*KB
+#define GB MB*KB
+
+#ifdef WIN32
+    #define SEC 1000
+#else
+    #define SEC 1
+#endif
+
+#define NF -1
+#define AC 0
+#define PE 1
+#define WA 2
+#define JE 3
+#define TL 4
+
+using namespace std;
+
+class solution {
+ public:
+  string execName;
+  vector<string> inputs;
+  vector<string> outputs;
+  
+  solution();
+  int compare_solution(string fto_comp, int outputN);
+  void show_solution(string fto_comp, int outputN, FILE * report);
+    
+  
+ private:
+  string get_file(FILE * fin);
+  bool file_comp(FILE * fin1, FILE * fin2, bool blanks);
+};
+
+extern FILE * config;
+extern vector<solution> sols;
+extern string outputName;
+extern int timeLimit;
+
+string get_command(string exec, string input);
+bool kill_proc(string procName);
+void kill_time(int secs);
+string get_erase_cmd(string outputName);
+void test();
+void start_grader();
+bool try_open(char * fname);
+#endif
-#include "grader.cpp"
-
-using namespace std;
+#include <grader.h>
 
 int main(int argc, char ** argv) {
     if(argc <= 1) {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.