• + 0 comments

    This is so over the top, but I refuse to do it otherwise

    class BinaryString {
    public:
        std::string value;
    
        BinaryString(const std::string& bin_str) : value(bin_str) {}
    
        // Overload the + operator
        BinaryString operator+(const BinaryString& other) const {
            std::string result = "";
            
            for (int i = 0; i<value.size(); i++) {
                if(value[i]=='1' || other.value[i]=='1'){
                    result+="1";
                }
            }
            std::reverse(result.begin(), result.end());
            return BinaryString(result);
        }
    };
    
    
    
    vector<int> acmTeam(vector<string> topic) {
        int subjects = 0;
        int knowitalls = 0;
        std::vector<BinaryString> teams;
        std::transform(topic.begin(), topic.end(), std::back_inserter(teams), [](const std::string& s) { return BinaryString(s); });
        
        for(int i = 0; i<teams.size(); i++){
            for(int j = i+1; j<teams.size(); j++){
                 BinaryString team_sum = teams[i] + teams[j];
                 
                 if(team_sum.value.size()>subjects){
                    subjects = team_sum.value.size();
                    knowitalls = 0;
                 }
                 
                if(team_sum.value.size()==subjects){
                    knowitalls++;
                 }
            }
        }
        
        
        return {subjects, knowitalls};
    }