Camel Case 4

Sort by

recency

|

553 Discussions

|

  • + 0 comments

    public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner sc = new Scanner(System.in);
        List<String> lines = new ArrayList<>();
    
        // Keep reading until EOF (no more lines)
        while (sc.hasNextLine()) {
            String line = sc.nextLine();
            lines.add(line);
        }
        for (String s : lines) {
            System.out.println(createOrSplitCamelCaseMethod(s));
        }
    }
    
    public static String createOrSplitCamelCaseMethod(String str) {
        String [] strArr = str.split(";");
        String finalStr = "";
        int j = 0;
        if(strArr[0].equals("S")){
            if(strArr[1].equals("M") || strArr[1].equals("V")|| strArr[1].equals("C")){
                strArr[2] = strArr[2].replace("()", "");
               for(int i =0; i< strArr[2].length(); i ++){
                       if (strArr[1].equals("C")) {
                           if(i ==0)
                            continue;
                       }
                    if(Character.isUpperCase(strArr[2].charAt(i)) && j ==0){
                            finalStr = strArr[2].substring(j, i);
                            j = i;
                    }else if(Character.isUpperCase(strArr[2].charAt(i)) && j !=0) {
                        finalStr = finalStr + " " + strArr[2].substring(j, i);
                        j = i;
                    }else if(i == strArr[2].length()-1) {
                        finalStr = finalStr + " " + strArr[2].substring(j);
                    }
                }
                finalStr = finalStr.toLowerCase();
            }
        }else if(strArr[0].equals("C")){
           String strArr3 [] = strArr[2].split(" ");
           for(int i =0; i < strArr3.length; i ++){
            if(i ==0 && !strArr[1].equals("C")){
                finalStr = strArr3[0];
            }else{
                finalStr = finalStr + Character.toUpperCase(strArr3[i].charAt(0));
                finalStr = finalStr + strArr3[i].substring(1);
            }
           } 
            if(strArr[1].equals("M")){  
                finalStr = finalStr + "()";    
            }
        }  
        return finalStr;
    }
    

    }

  • + 0 comments

    sweatTea() yum

  • + 0 comments
    function capitalize(word) {
        return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
    }
    
    function combineOperation(parts, indicator) {
        const camelCase = parts.map((part,index) => index === 0 ? part.toLowerCase() : capitalize(part)).join("")
        if (indicator === "M" || indicator === "V" ) return indicator === "M" ? camelCase + "()" : camelCase
        return parts.map(capitalize).join("")
    }     
    
    function processData(input) {
        const parts = input.split("\r\n");
        parts.forEach(part => {
            const [operate, indicator, string] = part.split(";")
            const cleanString = string.replace(/[^a-zA-Z\s]/g, "");
            
            const ouput = operate === "S" 
            ? cleanString.split(/(?=[A-Z])/).join(" ").toLowerCase() 
            : combineOperation(cleanString.split(" "), indicator)
            
            console.info(ouput)
        })
    } 
     
    process.stdin.resume();
    process.stdin.setEncoding("ascii");
    _input = "";
    process.stdin.on("data", function (input) {
        _input += input;
    });
    
    process.stdin.on("end", function () {
       processData(_input);
    });
    
  • + 0 comments

    Python3 Correct Outputs but Wrong Answer Solution

    inputData = [line.rstrip('\n\r') for line in sys.stdin.readlines()]

  • + 0 comments

    Please help me on my program as this is not working altjough getting correct output:

    include

    #include <cstdio>
    

    include

    include

    include

    using namespace std;

    int main() {

    string s;
    

    while (getline(cin, s)) {

    int n=s.size();
    if(s[0] == 'S' && s[2]=='M' && s[n-1]== ')'){
    
      for(int i=4 ; i<n-2 ; i++){
        if (isupper(s[i])) {
          cout << " " << (char)tolower(s[i]);
        } else {
          cout << s[i];
        }
      }
      cout<<endl;
    }
    if(s[0]=='C' && s[2]=='V'){
    
      for(int i=4 ; i<n ; i++){
        if ((s[i]) == ' ') {
          cout << (char)toupper(s[i+1]);
          i++;
        } else {
          cout << s[i];
        }
      }
      cout<<endl;
    
    }
    
    if(s[0] == 'C' && s[2]=='C' ){
    
      cout<< (char)toupper(s[4]);
      for(int i=5 ; i<n ; i++){
        if ((s[i]) == ' ') {
          cout << (char)toupper(s[i+1]);
          i++;
        } else {
          cout << s[i];
        }
    
      }
      cout<<endl;
    }
    
    if(s[0] == 'S' && s[2]=='C' ){
          cout<< (char)tolower(s[4]);
    
      for(int i=5 ; i<n ; i++){
        if (isupper(s[i])) {
          cout << ' ' << (char)tolower(s[i]);
    
        } else {
          cout << s[i];
        }
      }
      cout<<endl;
    }
    
    if(s[0] == 'C' && s[2]=='M' ){
    
      string r;
      for(int i=4 ; i<n ; i++){
    
        if ((s[i]) == ' ') {
          r=r+(char)toupper(s[i+1]);
          i++;
    
    
        } else {
          r=r+s[i];
        }
      }
      r=r+"()";
      cout << r <<endl;
    
    }
    
    if(s[0] == 'S' && s[2]=='V' ){
          cout<< (char)tolower(s[4]);
    
      for(int i=5 ; i<n ; i++){
        if (isupper(s[i])) {
          cout << ' ' << (char)tolower(s[i]);
    
        } else {
          cout << s[i];
        }
      }
      cout<<endl;
    }
    

    } /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    return 0; }