We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
if (T == 0) { cout << Server::getLoad() + a<<endl; why this is used can anyone explain?
If the bad_alloc exception is thrown then the Server::compute() call is not made for test case T and the Server::load value is not incremented and the last line of output will be wrong. To workaround this problem, the static variable a is used to keep count of how many test cases this happens and when T reaches zero, the value of a is added to the value returned by Server::getLoad() in order to print the corrected value on the last line of output. Furthermore, the statement return 0; causes the main block to exit, preventing in the protected code, the call to Server::getLoad() and the printing of its returned value.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Exceptional Server
You are viewing a single comment's thread. Return to all comments →
Your entire comment :
If the bad_alloc exception is thrown then the Server::compute() call is not made for test case T and the Server::load value is not incremented and the last line of output will be wrong. To workaround this problem, the static variable a is used to keep count of how many test cases this happens and when T reaches zero, the value of a is added to the value returned by Server::getLoad() in order to print the corrected value on the last line of output. Furthermore, the statement return 0; causes the main block to exit, preventing in the protected code, the call to Server::getLoad() and the printing of its returned value.