Inherited Code Discussions | C++ | HackerRank

Inherited Code

Sort by

recency

|

227 Discussions

|

  • + 0 comments

    Cricaza online brings several digital gaming categories together within a single platform. Instead of navigating multiple websites, users can explore different entertainment formats through one structured system. The platform offers a quick signup process that allows new users to create accounts easily. After registration, users can log in securely and access their dashboard. Cricaza’s mobile-friendly design ensures that the platform performs smoothly across devices. With clear menus and organized sections, Cricaza simplifies navigation and helps users discover various gaming options. The platform continues to attract users who value flexibility and accessibility in digital gaming.

  • + 0 comments

    Am I dense, or does the locked code stub not exist for C++20?

  • + 0 comments

    Use runtime_error and explicit

    class BadLengthException : public runtime_error {
    public:
        explicit BadLengthException(int n) : runtime_error(to_string(n)) {}
    };
    
  • + 0 comments

    class BadLengthException{ private: int n; //Length

    public:
        BadLengthException(int errornumber){
            n = errornumber; //
        }
         int what(){
            return n;
        };
    

    };

  • + 0 comments
    #include <iostream>
    #include <string>
    #include <sstream>
    #include <exception>
    using namespace std;
    
    
    class BadLengthException : public exception
    {
    private:
        string msg;
    
    public:
        BadLengthException(int length) : msg(to_string(length)) {}
    
        virtual const char *what() const noexcept override
        {
            return msg.c_str();
        }
    };
    
    
    bool checkUsername(string username) {
    	bool isValid = true;
    	int n = username.length();
    	if(n < 5) {
    		throw BadLengthException(n);
    	}
    	for(int i = 0; i < n-1; i++) {
    		if(username[i] == 'w' && username[i+1] == 'w') {
    			isValid = false;
    		}
    	}
    	return isValid;
    }
    
    int main() {
    	int T; cin >> T;
    	while(T--) {
    		string username;
    		cin >> username;
    		try {
    			bool isValid = checkUsername(username);
    			if(isValid) {
    				cout << "Valid" << '\n';
    			} else {
    				cout << "Invalid" << '\n';
    			}
    		} catch (BadLengthException e) {
    			cout << "Too short: " << e.what() << '\n';
    		}
    	}
    	return 0;
    }