Źródło: spoj.com
Sędzia na platformie spoj.com, który blokuje frazy: sort, qsort, define:
#include <spoj.h>
#include <cstdio>
#include <cstring>
const int MAX_LENGTH = 50000;
const int NO_KEYWORDS = 3;
int main()
{
spoj_init();
int test, sig, mem, memMax = 0, len = 0, ch;
bool ok = true;
double score, time, timeAll = 0;
char status[4];
char keywords[][10] = {"sort", "qsort", "define"};
int occurrences[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
char program[MAX_LENGTH+9];
// reading user's program
while((ch = getc(spoj_t_src)) != EOF)
program[len++] = ch;
// checking for banned keywords
char bed[20];
for(int i = 0; i < len; ++i)
{
// for each banned keywords
for(int j = 0; j < NO_KEYWORDS; ++j)
// if banned keyword was found and it occurred too many times return WA
if(!strncmp(program+i, keywords[j], strlen(keywords[j])) && !occurrences[j]--)
{
ok = false;
strcpy(bed,keywords[j]);
break;
}
if(!ok)
break;
}
if(!ok)
{
fprintf(spoj_score,"RE 0 9 0 0 niedozwolone frazy: %s \n",bed);
return 0;
}
// while there are judges' results
while(fscanf(spoj_p_in, "%d %3s %lf %d %lf %d\n", &test, status, &score, &sig, &time, &mem) == 6)
{
// print the result description to ps_info
fprintf(spoj_p_info, "test %d - %s (score=%lf, sig=%d, time=%lf, mem=%d)\n", test, status, score, sig, time, mem);
if(mem > memMax)
memMax = mem;
if(timeAll >= 0)
if(time >= 0)
timeAll += time;
else
timeAll = -1;
if(status[0] != 'A')
{
fprintf(spoj_score, "%s 0 %d %lf %d\n", status, sig, timeAll, memMax);
return 0;
}
}
fprintf(spoj_score, "AC 0 0 %lf %d\n", timeAll, memMax);
return 0;
}
Sędzia na platformie spoj.com, którynadaje punkty oddzielnie dla każdego testu:
#include <stdio.h>
#include <spoj.h>
#include <errno.h>
#include <string.h>
//liczba testów
#define NOT 5
using namespace std;
int main()
{
spoj_init();
double scoreAll=0;
double timeSUM=0;
int memMax=0;
int i, nott;
int test[NOT];
char status[NOT][4];
char mstatus[NOT][64];
double score[NOT];
int sig[NOT];
double time[NOT];
int timelimit[NOT] = {1,1,1,1,1}; //limit czasowy dla kazdego testu
double scorept[NOT] = {1,1,1,1,2}; //liczba punków dla poszczegolnych testow
double scorelimit = 2; //minimalny próg zaliczenia zadania
int mem[NOT];
for(i=0; fscanf(spoj_p_in, "%d %3s %lf %d %lf %d\n", &test[i], status[i], &score[i], &sig[i], &time[i], &mem[i])==6;i++)
{
if (status[i][0]=='A')
{
scoreAll+=scorept[i];
timeSUM+=time[i];
if (memMax<mem[i])
memMax=mem[i];
}
strcpy(mstatus[i],"blšd systemu");
if (status[i][0]=='A') strcpy(mstatus[i],"brawo!!");
if (status[i][0]=='R')
{
strcpy(mstatus[i],"runtime error");
switch (sig[i])
{
case -1: strcat(mstatus[i]," (NZEC)"); break;
case 6: strcat(mstatus[i]," (SIGABRT)"); break;
case 8: strcat(mstatus[i]," (SIGFPE)"); break;
case 11: strcat(mstatus[i]," (SIGSEGV)"); break;
case 25: strcat(mstatus[i]," (SIGXFSZ)");
}
}
if (status[i][0]=='T') strcpy(mstatus[i],"przekroczono limit czasu");
if (status[i][0]=='W') strcpy(mstatus[i],"bledna odpowied?");
}
nott = i;
fprintf(spoj_u_info, "<table class='navigation' width='99\%'>");
fprintf(spoj_u_info, "<tr class='headerrow'>");
fprintf(spoj_u_info, "<th class='headerrowleft'><font color=yellow>Test case</font></th><th><font color=yellow>Points</font></th>");
fprintf(spoj_u_info, "<th class='headerrowright'><font color=yellow>Result<br>(running time : time limit)</font></th>");
for(i=0;i<nott;i++)
{
fprintf(spoj_u_info,"<tr class='problemrow'> <td class=%s align=center width=15%><font color=navy>%d</font></td> <td class=%s align=center width=15%><font color=navy>%.1lf pts</font></td>", (status[i][0]=='A')?"kol3":"kol", i+1,(status[i][0]=='A')?"kol3":"kol", scorept[i]);
if (time[i] >= 0)
fprintf(spoj_u_info,"<td class=%s align=center><font color=black>%s<br>(%.2lfs : %ds)</font></td>", (status[i][0]=='A')?"kol3":"kol", mstatus[i], time[i], timelimit[i]);
else
fprintf(spoj_u_info, "<td class=%s align=center><font color=black>%s<br>(> %ds : %ds)</font></td></tr>", (status[i][0]=='A')?"kol3":"kol", mstatus[i], 2*timelimit[i], timelimit[i]);
}
if (scoreAll >= scorelimit)
fprintf(spoj_u_info, "<tr class='problemrow'><td align=center colspan=3 style='background-color: navy; font-size: 16px; font-weight: bold;'><font color=yellow><b>Score: %.0lf</b></font></td></tr>", scoreAll);
else
fprintf(spoj_u_info, "<tr class='problemrow'><td align=center colspan=3 style='background-color: navy; font-size: 16px; font-weight: bold;'><font color=orange><b>Score: %.0lf</b></font></tr></td>", scoreAll);
fprintf(spoj_u_info, "</table>");
if (scoreAll >= scorelimit)
fprintf(spoj_score, "AC %.1lf 0 %lf %d\n", scoreAll, timeSUM, memMax);
else
fprintf(spoj_score, "SE %.1lf 0 %lf %d (limit: %.0lf)\n", scoreAll, timeSUM, memMax, scorelimit);
}