-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathexceptional-server.cpp
More file actions
77 lines (69 loc) · 1.83 KB
/
exceptional-server.cpp
File metadata and controls
77 lines (69 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Exceptional Server
// Handle server errors.
//
// https://www.hackerrank.com/challenges/exceptional-server/problem
//
// les gars d'hackerrank n'assoient un peu sur la qualité et la sécurité du code
// après, faut pas s'étonner de la qualité du code industrialisé...
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wsign-conversion"
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wfloat-conversion"
// de plus, ce challenge ne fonctionne pas avec clang, il est ni pertinent
// ni judicieux
#include <iostream>
#include <exception>
#include <string>
#include <stdexcept>
#include <vector>
#include <cmath>
using namespace std;
class Server {
private:
static int load;
public:
static int compute(long long A, long long B) {
load += 1;
if(A < 0) {
throw std::invalid_argument("A is negative");
}
vector<int> v(A, 0);
int real = -1, cmplx = sqrt(-1);
if(B == 0) throw 0;
real = (A/B)*real;
int ans = v.at(B);
return real + A - B*ans;
}
static int getLoad() {
return load;
}
};
int Server::load = 0;
int main() {
int T; cin >> T;
while(T--) {
long long A, B;
cin >> A >> B;
// (skeliton_head) ----------------------------------------------------------------------
/* Enter your code here. */
try {
cout << Server::compute(A, B) << endl;
}
catch (bad_alloc& e)
{
cout << "Not enough memory" << endl;
}
catch (exception& e)
{
cout << "Exception: " << e.what() << endl;
}
catch (...)
{
cout << "Other Exception" << endl;
}
// (skeliton_tail) ----------------------------------------------------------------------
}
cout << Server::getLoad() << endl;
return 0;
}