Skip to content

Commit ffc6180

Browse files
author
esulaimanov
committed
another srm
1 parent edfd434 commit ffc6180

File tree

4 files changed

+418
-1
lines changed

4 files changed

+418
-1
lines changed

BuyOneGetOneFree.cpp

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#include <vector>
2+
#include <list>
3+
#include <map>
4+
#include <set>
5+
#include <queue>
6+
#include <deque>
7+
#include <stack>
8+
#include <bitset>
9+
#include <algorithm>
10+
#include <functional>
11+
#include <numeric>
12+
#include <utility>
13+
#include <sstream>
14+
#include <iostream>
15+
#include <iomanip>
16+
#include <cstdio>
17+
#include <cmath>
18+
#include <cstdlib>
19+
#include <ctime>
20+
21+
using namespace std;
22+
23+
24+
class BuyOneGetOneFree {
25+
public:
26+
int buy(vector <int> prices) {
27+
sort(prices.rbegin(),prices.rend());
28+
29+
int sum = 0;
30+
for (int i = 0; i < prices.size(); i += 2) {
31+
sum += prices[i];
32+
}
33+
return sum;
34+
}
35+
};
36+
37+
38+
// BEGIN KAWIGIEDIT TESTING
39+
// Generated by KawigiEdit 2.1.4 (beta) modified by pivanof
40+
bool KawigiEdit_RunTest(int testNum, vector <int> p0, bool hasAnswer, int p1) {
41+
cout << "Test " << testNum << ": [" << "{";
42+
for (int i = 0; int(p0.size()) > i; ++i) {
43+
if (i > 0) {
44+
cout << ",";
45+
}
46+
cout << p0[i];
47+
}
48+
cout << "}";
49+
cout << "]" << endl;
50+
BuyOneGetOneFree *obj;
51+
int answer;
52+
obj = new BuyOneGetOneFree();
53+
clock_t startTime = clock();
54+
answer = obj->buy(p0);
55+
clock_t endTime = clock();
56+
delete obj;
57+
bool res;
58+
res = true;
59+
cout << "Time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " seconds" << endl;
60+
if (hasAnswer) {
61+
cout << "Desired answer:" << endl;
62+
cout << "\t" << p1 << endl;
63+
}
64+
cout << "Your answer:" << endl;
65+
cout << "\t" << answer << endl;
66+
if (hasAnswer) {
67+
res = answer == p1;
68+
}
69+
if (!res) {
70+
cout << "DOESN'T MATCH!!!!" << endl;
71+
} else if (double(endTime - startTime) / CLOCKS_PER_SEC >= 2) {
72+
cout << "FAIL the timeout" << endl;
73+
res = false;
74+
} else if (hasAnswer) {
75+
cout << "Match :-)" << endl;
76+
} else {
77+
cout << "OK, but is it right?" << endl;
78+
}
79+
cout << "" << endl;
80+
return res;
81+
}
82+
int main() {
83+
bool all_right;
84+
all_right = true;
85+
86+
vector <int> p0;
87+
int p1;
88+
89+
{
90+
// ----- test 0 -----
91+
int t0[] = {47};
92+
p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
93+
p1 = 47;
94+
all_right = KawigiEdit_RunTest(0, p0, true, p1) && all_right;
95+
// ------------------
96+
}
97+
98+
{
99+
// ----- test 1 -----
100+
int t0[] = {10,20};
101+
p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
102+
p1 = 20;
103+
all_right = KawigiEdit_RunTest(1, p0, true, p1) && all_right;
104+
// ------------------
105+
}
106+
107+
{
108+
// ----- test 2 -----
109+
int t0[] = {10,20,30,20};
110+
p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
111+
p1 = 50;
112+
all_right = KawigiEdit_RunTest(2, p0, true, p1) && all_right;
113+
// ------------------
114+
}
115+
116+
{
117+
// ----- test 3 -----
118+
int t0[] = {5,7,13,2,9};
119+
p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
120+
p1 = 22;
121+
all_right = KawigiEdit_RunTest(3, p0, true, p1) && all_right;
122+
// ------------------
123+
}
124+
125+
{
126+
// ----- test 4 -----
127+
int t0[] = {100,100,100,100,100,100};
128+
p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
129+
p1 = 300;
130+
all_right = KawigiEdit_RunTest(4, p0, true, p1) && all_right;
131+
// ------------------
132+
}
133+
134+
if (all_right) {
135+
cout << "You're a stud (at least on the example cases)!" << endl;
136+
} else {
137+
cout << "Some of the test cases had errors." << endl;
138+
}
139+
return 0;
140+
}
141+
// END KAWIGIEDIT TESTING
142+
//Powered by KawigiEdit 2.1.4 (beta) modified by pivanof!

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
cmake_minimum_required(VERSION 3.12)
22
project(topcoder)
3-
add_executable(topcoder DivideLoot.cpp)
3+
add_executable(topcoder PairedMultiples.cpp)
44
ADD_DEFINITIONS(-std=c++11)

FriendFinder.cpp

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#include <vector>
2+
#include <list>
3+
#include <map>
4+
#include <set>
5+
#include <queue>
6+
#include <deque>
7+
#include <stack>
8+
#include <bitset>
9+
#include <algorithm>
10+
#include <functional>
11+
#include <numeric>
12+
#include <utility>
13+
#include <sstream>
14+
#include <iostream>
15+
#include <iomanip>
16+
#include <cstdio>
17+
#include <cmath>
18+
#include <cstdlib>
19+
#include <ctime>
20+
21+
using namespace std;
22+
23+
24+
class FriendFinder {
25+
public:
26+
int distance(string line) {
27+
int x = line.find('F');
28+
int y = line.find('S');
29+
return abs(x - y);
30+
}
31+
};
32+
33+
34+
// BEGIN KAWIGIEDIT TESTING
35+
// Generated by KawigiEdit 2.1.4 (beta) modified by pivanof
36+
bool KawigiEdit_RunTest(int testNum, string p0, bool hasAnswer, int p1) {
37+
cout << "Test " << testNum << ": [" << "\"" << p0 << "\"";
38+
cout << "]" << endl;
39+
FriendFinder *obj;
40+
int answer;
41+
obj = new FriendFinder();
42+
clock_t startTime = clock();
43+
answer = obj->distance(p0);
44+
clock_t endTime = clock();
45+
delete obj;
46+
bool res;
47+
res = true;
48+
cout << "Time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " seconds" << endl;
49+
if (hasAnswer) {
50+
cout << "Desired answer:" << endl;
51+
cout << "\t" << p1 << endl;
52+
}
53+
cout << "Your answer:" << endl;
54+
cout << "\t" << answer << endl;
55+
if (hasAnswer) {
56+
res = answer == p1;
57+
}
58+
if (!res) {
59+
cout << "DOESN'T MATCH!!!!" << endl;
60+
} else if (double(endTime - startTime) / CLOCKS_PER_SEC >= 2) {
61+
cout << "FAIL the timeout" << endl;
62+
res = false;
63+
} else if (hasAnswer) {
64+
cout << "Match :-)" << endl;
65+
} else {
66+
cout << "OK, but is it right?" << endl;
67+
}
68+
cout << "" << endl;
69+
return res;
70+
}
71+
int main() {
72+
bool all_right;
73+
all_right = true;
74+
75+
string p0;
76+
int p1;
77+
78+
{
79+
// ----- test 0 -----
80+
p0 = "....SF...";
81+
p1 = 1;
82+
all_right = KawigiEdit_RunTest(0, p0, true, p1) && all_right;
83+
// ------------------
84+
}
85+
86+
{
87+
// ----- test 1 -----
88+
p0 = "S........F";
89+
p1 = 9;
90+
all_right = KawigiEdit_RunTest(1, p0, true, p1) && all_right;
91+
// ------------------
92+
}
93+
94+
{
95+
// ----- test 2 -----
96+
p0 = "..F...S..";
97+
p1 = 4;
98+
all_right = KawigiEdit_RunTest(2, p0, true, p1) && all_right;
99+
// ------------------
100+
}
101+
102+
if (all_right) {
103+
cout << "You're a stud (at least on the example cases)!" << endl;
104+
} else {
105+
cout << "Some of the test cases had errors." << endl;
106+
}
107+
return 0;
108+
}
109+
// END KAWIGIEDIT TESTING
110+
//Powered by KawigiEdit 2.1.4 (beta) modified by pivanof!

0 commit comments

Comments
 (0)