We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
PHP Language here. Any ideas on what's wrong with my code?
Parentheses "()" always goes to the next line.
$_fp=fopen("php://stdin","r");/* Enter your code here. Read input from STDIN. Print output to STDOUT */$process=['S','C'];$name=['C','M','V'];while(!feof($_fp)){$input=fgets($_fp);$word=substr($input,4);echo($input[0]=='S')?splitWord($word):combineWord($word,$input[2]);}functionsplitWord($word){preg_match_all('/[A-Z]/',$word,$matches,PREG_OFFSET_CAPTURE);foreach($matches[0]as$letter){if($letter[1]==0){$word[$letter[1]]=strtolower($letter[0]);}else{$word=str_replace($letter[0]," ".strtolower($letter[0]),$word);}}if(substr($word,-2)=='()'){$word=str_replace("()","",$word);}return$word;}functioncombineWord($word,$process){$arr=explode(' ',$word);foreach($arras&$phrase){switch($process){case'C':$phrase=ucfirst($phrase);break;case('V'||'M'):$phrase=($arr[0]!==$phrase)?ucfirst($phrase):$phrase;break;}}if($process=='M'){array_push($arr,"()");}$word=implode('',$arr);return$word;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Camel Case 4
You are viewing a single comment's thread. Return to all comments →
PHP Language here. Any ideas on what's wrong with my code?
Parentheses "()" always goes to the next line.