Input is to be taken from a-z or A-Z. We need to have the first and last Capital letters of that input string as the output

泪湿孤枕 提交于 2019-12-13 11:15:16

问题


Input is to be taken from a-z or A-Z and the input ends when we give a star(*). We need to have the first and last Capital letters of that input characters as the output. also, we should show the input we have taken each time. N.B. We take the inuputs character by character, not as a string.

Test case 1: input: aAbCcP* output: AP

Test case 2: input: ZabCBc* output: ZB


回答1:


    $test1="aAbCcP*";
    $test="ZabCBc*";
    $i=0;
    $a=[];
    $final_string="";
    while(!empty($test[$i])){ 
        if(ctype_upper($test[$i])){
            $final_string=$test[$i];
            array_push($a,$final_string);
        }
        $i++;
  }
  $first = reset($a);
$last = end($a);

  echo  $first. $last;


来源:https://stackoverflow.com/questions/56765729/input-is-to-be-taken-from-a-z-or-a-z-we-need-to-have-the-first-and-last-capital

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!