Exceptional Server

Sort by

recency

|

176 Discussions

|

  • + 0 comments
    #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;
    
            try
            {
                cout << Server::compute(A, B) << endl;
            }
            catch (const std::bad_alloc &e)
            {
                cout << "Not enough memory" << endl;
            }
            catch (const std::exception &e)
            {
                cout << "Exception: " << e.what() << endl;
            }
            catch (...)
            {
                cout << "Other Exception" << endl;
            }
    	}
    	cout << Server::getLoad() << endl;
    	return 0;
    }
    
  • + 0 comments

    I seem to be missing something here, what function to call to get its output?

  • + 0 comments

    In the Java ecosystem, "server" could mean a web server, an application server, or even a backend service—basically, a component that processes requests and delivers responses over a network. 11xplay

  • + 0 comments
    try {
                cout<< Server::compute(A, B) << endl;
            } catch (const bad_alloc& e) {
                cout << "Not enough memory" << endl;
            } catch (const exception& e) {
                cout << "Exception: " << e.what() << endl;
            }  catch (...) {
                cout << "Other Exception" << endl;
            }
    
  • + 0 comments

    Here is Exceptional Server problem solution in C++ - https://programmingoneonone.com/hackerrank-exceptional-server-solution-in-cpp.html