S
S
skesS2019-10-13 08:39:36
Pascal
skesS, 2019-10-13 08:39:36

How can I print the second of the words that start with C, even though there may be several spaces between the words in the line?

Also, spaces can be at the beginning or at the end of a line.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stockholm Syndrome, 2019-10-13
@StockholmSyndrome

program abc; 
var 
  str: string; 
  i: Integer;
begin 
  ReadLn(str);
  i := 0;
  
  foreach w: string in Regex.Split(str, ' +') do begin 
    if w[1] = 'С' then begin 
      Inc(i);
      if i = 2 then begin
        WriteLn(w);
        break;
      end;
    end;
  end;
end.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question