Download code/validation/C++/0009937_TheDevice.cpp from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 4.86 kB
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/code/validation/C%2B%2B/0009937_TheDevice.cpp
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/code/validation/C++/0009937_TheDevice.cpp
-
curl -L -o 0009937_TheDevice.cpp https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/code/validation/C%2B%2B/0009937_TheDevice.cpp
4.86 kB
| using namespace std; | |
| struct TheDevice { | |
| int minimumAdditional(vector <string> plates) { | |
| int m = 0; | |
| fori (j, plates[0]) { | |
| int c = 0; | |
| fori(i, plates) | |
| c += plates[i][j] - '0'; | |
| m = max(m, max(2 - c, 0) + max(1 - (int)plates.size() + c, 0)); | |
| } | |
| return m; | |
| } | |
| }; | |
| double test0() { | |
| string t0[] = {"010", | |
| "011", | |
| "101"}; | |
| vector <string> p0(t0, t0+sizeof(t0)/sizeof(string)); | |
| TheDevice * obj = new TheDevice(); | |
| clock_t start = clock(); | |
| int my_answer = obj->minimumAdditional(p0); | |
| clock_t end = clock(); | |
| delete obj; | |
| cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl; | |
| int p1 = 1; | |
| cout <<"Desired answer: " <<endl; | |
| cout <<"\t" << p1 <<endl; | |
| cout <<"Your answer: " <<endl; | |
| cout <<"\t" << my_answer <<endl; | |
| if (p1 != my_answer) { | |
| cout <<"DOESN'T MATCH!!!!" <<endl <<endl; | |
| return -1; | |
| } | |
| else { | |
| cout <<"Match :-)" <<endl <<endl; | |
| return (double)(end-start)/CLOCKS_PER_SEC; | |
| } | |
| } | |
| double test1() { | |
| string t0[] = {"0", | |
| "1", | |
| "0", | |
| "1"}; | |
| vector <string> p0(t0, t0+sizeof(t0)/sizeof(string)); | |
| TheDevice * obj = new TheDevice(); | |
| clock_t start = clock(); | |
| int my_answer = obj->minimumAdditional(p0); | |
| clock_t end = clock(); | |
| delete obj; | |
| cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl; | |
| int p1 = 0; | |
| cout <<"Desired answer: " <<endl; | |
| cout <<"\t" << p1 <<endl; | |
| cout <<"Your answer: " <<endl; | |
| cout <<"\t" << my_answer <<endl; | |
| if (p1 != my_answer) { | |
| cout <<"DOESN'T MATCH!!!!" <<endl <<endl; | |
| return -1; | |
| } | |
| else { | |
| cout <<"Match :-)" <<endl <<endl; | |
| return (double)(end-start)/CLOCKS_PER_SEC; | |
| } | |
| } | |
| double test2() { | |
| string t0[] = {"01010101", | |
| "10101010"}; | |
| vector <string> p0(t0, t0+sizeof(t0)/sizeof(string)); | |
| TheDevice * obj = new TheDevice(); | |
| clock_t start = clock(); | |
| int my_answer = obj->minimumAdditional(p0); | |
| clock_t end = clock(); | |
| delete obj; | |
| cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl; | |
| int p1 = 1; | |
| cout <<"Desired answer: " <<endl; | |
| cout <<"\t" << p1 <<endl; | |
| cout <<"Your answer: " <<endl; | |
| cout <<"\t" << my_answer <<endl; | |
| if (p1 != my_answer) { | |
| cout <<"DOESN'T MATCH!!!!" <<endl <<endl; | |
| return -1; | |
| } | |
| else { | |
| cout <<"Match :-)" <<endl <<endl; | |
| return (double)(end-start)/CLOCKS_PER_SEC; | |
| } | |
| } | |
| double test3() { | |
| string t0[] = {"10010101011", | |
| "00010101001", | |
| "00100010111", | |
| "00101010101", | |
| "01010111101"}; | |
| vector <string> p0(t0, t0+sizeof(t0)/sizeof(string)); | |
| TheDevice * obj = new TheDevice(); | |
| clock_t start = clock(); | |
| int my_answer = obj->minimumAdditional(p0); | |
| clock_t end = clock(); | |
| delete obj; | |
| cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl; | |
| int p1 = 1; | |
| cout <<"Desired answer: " <<endl; | |
| cout <<"\t" << p1 <<endl; | |
| cout <<"Your answer: " <<endl; | |
| cout <<"\t" << my_answer <<endl; | |
| if (p1 != my_answer) { | |
| cout <<"DOESN'T MATCH!!!!" <<endl <<endl; | |
| return -1; | |
| } | |
| else { | |
| cout <<"Match :-)" <<endl <<endl; | |
| return (double)(end-start)/CLOCKS_PER_SEC; | |
| } | |
| } | |
| double test4() { | |
| string t0[] = {"1101001011010", | |
| "0010000010101", | |
| "1010101011110", | |
| "1101010100111", | |
| "1011111110111"}; | |
| vector <string> p0(t0, t0+sizeof(t0)/sizeof(string)); | |
| TheDevice * obj = new TheDevice(); | |
| clock_t start = clock(); | |
| int my_answer = obj->minimumAdditional(p0); | |
| clock_t end = clock(); | |
| delete obj; | |
| cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl; | |
| int p1 = 0; | |
| cout <<"Desired answer: " <<endl; | |
| cout <<"\t" << p1 <<endl; | |
| cout <<"Your answer: " <<endl; | |
| cout <<"\t" << my_answer <<endl; | |
| if (p1 != my_answer) { | |
| cout <<"DOESN'T MATCH!!!!" <<endl <<endl; | |
| return -1; | |
| } | |
| else { | |
| cout <<"Match :-)" <<endl <<endl; | |
| return (double)(end-start)/CLOCKS_PER_SEC; | |
| } | |
| } | |
| int main() { | |
| int time; | |
| bool errors = false; | |
| time = test0(); | |
| if (time < 0) | |
| errors = true; | |
| time = test1(); | |
| if (time < 0) | |
| errors = true; | |
| time = test2(); | |
| if (time < 0) | |
| errors = true; | |
| time = test3(); | |
| if (time < 0) | |
| errors = true; | |
| time = test4(); | |
| if (time < 0) | |
| errors = true; | |
| if (!errors) | |
| cout <<"You're a stud (at least on the example cases)!" <<endl; | |
| else | |
| cout <<"Some of the test cases had errors." <<endl; | |
| } | |