C,
pasted
on Feb 21:
|
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
int ROUND(double x) { return (int)(x+0.5); }
bool ISINT(double x) { return fabs(ROUND(x)-x)<EPS; }
bool ISEQUAL(double x,double y) { return fabs(x-y)<EPS; }
#define PI (3.14159265358979323846)
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; }
double SQSUM(double x,double y) { return x*x+y*y; }
#define SZ(a) ((int)a.size())
class AgeEncoding {
public:
double getRadix(int age, string candlesLine) {
if(candlesLine.find('1')==string::npos) // 000000
{
return -1.0;
}
if(candlesLine.find('1')==SZ(candlesLine)-1) // 0001
{
if(age==1)
{
return -2.0;
}
else
{
return -1.0;
}
}
if(candlesLine[SZ(candlesLine)-1]=='1' && age==1 ) // 11, 1001, 000111
{
// base is zero
return -1.0;
}
double mi = 0.0;
double ma = 1000.0;
double base = mi + (ma-mi)/2.0;
for(int i=0;i<10000;i++)
{
double sum = 0.0;
double B = 1;
for(int n=0;n<SZ(candlesLine);n++)
{
sum += B*(candlesLine[SZ(candlesLine)-n-1]-'0');
B = B*base;
}
if(sum>age)
{
ma = base;
}
else
{
mi = base;
}
base = mi + (ma-mi)/2.0;
}
return base;
}
// 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(); if ((Case == -1) || (Case == 5)) test_case_5(); if ((Case == -1) || (Case == 6)) test_case_6(); }
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 double &Expected, const double &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
void test_case_0() { int Arg0 = 10; string Arg1 = "00010"; double Arg2 = 10.0; verify_case(0, Arg2, getRadix(Arg0, Arg1)); }
void test_case_1() { int Arg0 = 21; string Arg1 = "10101"; double Arg2 = 2.0; verify_case(1, Arg2, getRadix(Arg0, Arg1)); }
void test_case_2() { int Arg0 = 6; string Arg1 = "10100"; double Arg2 = 1.414213562373095; verify_case(2, Arg2, getRadix(Arg0, Arg1)); }
void test_case_3() { int Arg0 = 21; string Arg1 = "10111111110111101111111100111111110111111111111100"; double Arg2 = 0.9685012944510603; verify_case(3, Arg2, getRadix(Arg0, Arg1)); }
void test_case_4() { int Arg0 = 16; string Arg1 = "1"; double Arg2 = -1.0; verify_case(4, Arg2, getRadix(Arg0, Arg1)); }
void test_case_5() { int Arg0 = 1; string Arg1 = "1"; double Arg2 = -2.0; verify_case(5, Arg2, getRadix(Arg0, Arg1)); }
void test_case_6() { int Arg0 = 1; string Arg1 = "001000"; double Arg2 = 1.0; verify_case(6, Arg2, getRadix(Arg0, Arg1)); }
// END CUT HERE
};
// BEGIN CUT HERE
int main() {
AgeEncoding* ___test = new AgeEncoding();
___test->run_test(-1);
delete ___test;
}
// END CUT HERE
|
Output:
|
Line 17: error: cstdio: No such file or directory
Line 18: error: cstdlib: No such file or directory
Line 16: error: cmath: No such file or directory
Line 18: error: climits: No such file or directory
Line 17: error: cfloat: No such file or directory
Line 14: error: map: No such file or directory
Line 18: error: utility: No such file or directory
Line 14: error: set: No such file or directory
Line 19: error: iostream: No such file or directory
Line 17: error: memory: No such file or directory
Line 17: error: string: No such file or directory
Line 17: error: vector: No such file or directory
Line 20: error: algorithm: No such file or directory
Line 21: error: functional: No such file or directory
Line 18: error: sstream: No such file or directory
Line 18: error: complex: No such file or directory
Line 16: error: stack: No such file or directory
Line 16: error: queue: No such file or directory
Line 18: error: numeric: No such file or directory
Line 20: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'namespace'
Line 25: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'ISINT'
Line 26: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'ISEQUAL'
Line 28: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
Line 32: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'AgeEncoding'
In function 'main':
Line 110: error: 'AgeEncoding' undeclared (first use in this function)
Line 110: error: (Each undeclared identifier is reported only once
Line 110: error: for each function it appears in.)
Line 110: error: '___test' undeclared (first use in this function)
Line 110: error: 'new' undeclared (first use in this function)
Line 110: error: expected ';' before 'AgeEncoding'
Line 112: error: 'delete' undeclared (first use in this function)
Line 112: error: expected ';' before '___test'
|
|