Camel Case 4

  • + 0 comments

    Can someone please help why this code is failing

    #include <cmath>
    #include <cstdio>
    #include <vector>
    #include <iostream>
    #include <algorithm>
    #include <sstream>
    using namespace std;
    
    
    char makeCapitalLetter(const char c) {
        return c & (~(1<<5));
    }
    
    char makeSmallLetter(const char c) {
        return c | (1<<5);
    }
    
    
    string combineString(string raw, bool firstCapital=false, bool allCapital=true){
        stringstream ip{raw};
        string output = "";
        do {
            string word;
            ip>>word;
            
            if(allCapital) {
                word[0] = makeCapitalLetter(word[0]);
            }
            output+=word;
            
        }while(ip);
        
        if(!firstCapital) {
            output[0] = makeSmallLetter(output[0]);
        }
        return output;
    }
    
    string splitString(string raw) {
        string result = "";
        raw[0] = makeSmallLetter(raw[0]);
        for(auto c:raw) {
            if(isupper(c)) {
                result+=" ";
                result+=makeSmallLetter(c);
            }
            else {
                result+=c;
            }
        }
        return result;
    }
    
    int main() {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
        string line;
        while(getline(cin, line)) {
            stringstream ss{line};
            char cmd, type, tmp;
            string input, result;
            ss>>cmd>>tmp>>type>>tmp;
            getline(ss, input);
            
            #if 0
            cout<<cmd<<endl;
            cout<<type<<endl;
            cout<<input<<endl<<endl;
            #endif 
            
            switch (cmd) {
                case 'S':
                {
                    switch (type) {
                        case 'M': 
                            input = input.substr(0,input.size()-2);
                        case 'C': 
                        case 'V':
                            result = splitString(input);
                            break;
                        default:
                            break;
                    }
                }
                break;
                case 'C':
                {
                    switch (type) {
                        case 'M':
                        {
                            result = combineString(input);
                            result+="()";
                        }
                        break;
                        case 'C':
                        {
                            result = combineString(input, true);
                        }
                        break;
                        case 'V':
                        {
                            result = combineString(input);
                        }
                        break;
                        default:
                        {
                            
                        }
                    }
                }
                break;
            }
            
            cout<< result<< endl;
            
        }
        return 0;
    }