#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
typedef long long LL;
int gcd(int x, int y)
{
while(y) {
int t = x;
x = y;
y = t%y;
}
return x;
}
class GradingGridIns
{
public:
vector <string> score(vector <string> answer, vector <int> lower, vector <int> upper)
{
int lg = gcd(lower[0], lower[1]);
double la=lower[0]/lg, lb=lower[1]/lg;
int ug = gcd(upper[0], upper[1]);
double ua=upper[0]/ug, ub=upper[1]/ug;
vector<double> world;
char c[] = " ./0123456789";
for(int i=0; i<sizeof(c)-1; ++i)
for(int j=0; j<sizeof(c)-1; ++j)
for(int k=0; k<sizeof(c)-1; ++k)
for(int l=0; l<sizeof(c)-1; ++l) {
try {
double d = eval( string(1,c[i])+c[j]+c[k]+c[l] );
world.push_back(d);
} catch( const char* ) {
}
}
sort(world.begin(), world.end());
world.erase(unique(world.begin(), world.end()), world.end());
vector<double>::iterator lt = lower_bound( world.begin(), world.end(), la/lb );
vector<double>::iterator ut = upper_bound( world.begin(), world.end(), ua/ub );
if( lt!=world.begin() ) --lt;
vector<string> result(answer.size());
for(int i=0; i<answer.size(); ++i)
{
try {
double d = eval(answer[i]);
result[i] = (*lt<=d && (ut==world.end() || d<=*ut) ? "CORRECT" : "INCORRECT");
} catch( const char* ) {
result[i] = "MALFORMED";
}
}
return result;
}
static double eval( string ans )
{
int ii=0; while(ii<ans.size()&&ans[ii]==' ') ++ii;
ans = ans.substr(ii);
ii = ans.size(); while(ii>0 && ans[ii-1]==' ') --ii;
ans = ans.substr(0, ii);
int dot=-1, sla=-1, numdig=0;
int value = 0, value_pre = 0;
for(int i=0; i<ans.size(); ++i)
if( ans[i]=='.' )
{
if(dot>=0 || sla>=0)
throw "MALFORMED";
dot = i;
value_pre = value;
value = 0;
}
else if( ans[i]=='/' )
{
if(dot>=0 || sla>=0 || numdig==0 )
throw "MALFORMED";
sla = i;
value_pre = value;
value = 0;
}
else if( '0'<=ans[i] && ans[i]<='9' )
{
++numdig;
value = value*10 + ans[i]-'0';
}
else
throw "MALFORMED";
if(numdig==0)
throw "MALFORMED";
int L = value_pre, R = value;
if( sla >= 0 ) {
if( R == 0 )
throw "MALFORMED";
int g = gcd(L,R); L/=g, R/=g;
return L/double(R);
}
else if( dot >= 0 ) {
return L + R / pow(10.0, double(ans.size()-dot-1));
}
else {
return R;
}
}
// BEGIN CUT HERE
public:
void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); }
private:
template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
void verify_case(int Case, const vector <string> &Expected, const vector <string> &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: " << print_array(Expected) << endl; cerr << "\tReceived: " << print_array(Received) << endl; } }
void test_case_0() { string Arr0[] = {"4/7 "," 4/7","4/07","8/14",".571",".572"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {4,7}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); int Arr2[] = {4,7}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); string Arr3[] = {"CORRECT", "CORRECT", "CORRECT", "CORRECT", "CORRECT", "CORRECT" }; vector <string> Arg3(Arr3, Arr3 + (sizeof(Arr3) / sizeof(Arr3[0]))); verify_case(0, Arg3, score(Arg0, Arg1, Arg2)); }
void test_case_1() { string Arr0[] = {" 4/7","1.01","1.02"," 000"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {0,1}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); int Arr2[] = {1,1}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); string Arr3[] = {"CORRECT", "CORRECT", "INCORRECT", "CORRECT" }; vector <string> Arg3(Arr3, Arr3 + (sizeof(Arr3) / sizeof(Arr3[0]))); verify_case(1, Arg3, score(Arg0, Arg1, Arg2)); }
void test_case_2() { string Arr0[] = {"1.15","1 14","1.14"," 8/7"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {1142,1000}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); int Arr2[] = {1142,1000}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); string Arr3[] = {"INCORRECT", "MALFORMED", "CORRECT", "CORRECT" }; vector <string> Arg3(Arr3, Arr3 + (sizeof(Arr3) / sizeof(Arr3[0]))); verify_case(2, Arg3, score(Arg0, Arg1, Arg2)); }
void test_case_3() { string Arr0[] = {" ","...."," . ","1 23","8//5","9.4.","85/ ","/123","123/"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {1,1}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); int Arr2[] = {1,1}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); string Arr3[] = {"MALFORMED", "MALFORMED", "MALFORMED", "MALFORMED", "MALFORMED", "MALFORMED", "MALFORMED", "MALFORMED", "MALFORMED" }; vector <string> Arg3(Arr3, Arr3 + (sizeof(Arr3) / sizeof(Arr3[0]))); verify_case(3, Arg3, score(Arg0, Arg1, Arg2)); }
void test_case_4() { string Arr0[] = {"1/0 "}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arr1[] = {0,1}; vector <int> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); int Arr2[] = {9999,1}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); string Arr3[] = {"MALFORMED" }; vector <string> Arg3(Arr3, Arr3 + (sizeof(Arr3) / sizeof(Arr3[0]))); verify_case(4, Arg3, score(Arg0, Arg1, Arg2)); }
// END CUT HERE
};
// BEGIN CUT HERE
int main() { GradingGridIns().run_test(-1); }
// END CUT HERE