Algorithm/HackerRank

Jumping on the Clouds

hamaganatanadda 2019. 6. 26. 14:33

L : https://www.hackerrank.com/challenges/jumping-on-the-clouds/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=warmup

 

Q : 1을 피해서 점프를 몇 번하는가 ?..

 

A : 0인지 1인지 구분해서 값을 증가해서 처리

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
program jumpingOnClouds;
var
  iLen, ii, iVal, iZero, iResult : Longint;
begin
  Readln(iLen);
  iZero := 0;
  iResult := 0;
  for ii := 0 to iLen - 1 do 
  begin
    Read(iVal);
    if iVal = 0 then Inc(iZero);
    if (iZero >= 2) or (iVal = 1) then 
    begin 
      Inc(iResult);
      iZero := 0;
    end;
  end;
  Writeln(iResult);
end.
cs

'Algorithm > HackerRank' 카테고리의 다른 글

Repeated String  (0) 2019.06.26
Sock Merchant  (0) 2019.06.26