-3

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

  • 2
    Hi. Please learn https://stackoverflow.com/help/how-to-ask how to ask questions here. This is not a question and there is no code that you have tried. Generally, this platform is not a code writing service. We help with code that you've written. Thank you. – Brain Foo Long Jun 26 '19 at 05:34
  • 2
    Possible duplicate of [Finding first and last capital letter in user input](https://stackoverflow.com/questions/56819605/finding-first-and-last-capital-letter-in-user-input) – Peter Cordes Jun 29 '19 at 23:20

1 Answers1

-2
    $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;
  • 1
    please post context around your answer for future reading by others to understand it. – ZF007 Jun 26 '19 at 06:28
  • Using an unbounded amount of storage to record all the capitals isn't appropriate for a 16-bit x86 assembly question. Also, this appears to be some kind of high-level language similar to perl, or pseudocode. – Peter Cordes Jun 29 '19 at 23:24
  • @PeterCordes : it is PHP – Michael Petch Jun 30 '19 at 00:50
  • @MichaelPetch: oh right, been a while since I've done anything with PHP. This code also has a termination condition that doesn't translate to the actual problem: it's finding the end of an explicit-length string, not searching for a `'*'` terminator. So it's not even the right algorithm. – Peter Cordes Jun 30 '19 at 00:56