OnBoarding
접속주소
게임방법
다가오는 적기들을 물리쳐야 합니다.
적기들의 이름과 거리를 알려줍니다.
STDOUT 으로 이름을 출력하면, 해당 적기를 향해 미사일을 발사합니다.
모든 적기가 다가오기전에 모두 물리쳐야 합니다.
5 threats approaching fast ! Threats within range: HotDroid 60m HotDroid 60m HotDroid 60m HotDroid 60m Standard Output Stream: HotDroid
사용할 언어를 선택합니다.
Perl은 선택하면 아래와 같은 기본 코드가 제공됩니다.
$enemy 에는 적기의 이름이, $dist에는 적기와의 거리가 입력됩니다.
디버깅을 하려면, ''print STDERR "Debug messages...\n";'' 를 사용하면 됩니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | select (STDOUT); $| = 1; # DO NOT REMOVE # The code below will read all the game information for you. # On each game turn, information will be available on the standard input, you will be sent: # -> the total number of visible enemies # -> for each enemy, its name and distance from you # The system will wait for you to write an enemy name on the standard output. # Once you have designated a target: # -> the cannon will shoot # -> the enemies will move # -> new info will be available for you to read on the standard input. # game loop while (1) { chomp ( $count = <STDIN>); # The number of current enemy ships within range print STDERR "COUNT:" . $count . "\n" ; @enemies = (); for ( my $i =0; $i < $count ; $i ++) { # enemy: The name of this enemy # dist: The distance to your cannon of this enemy chomp ( $tokens =<STDIN>); ( $enemy , $dist ) = split (/ /, $tokens ); print STDERR "name:" . $enemy . "\tdist:" . $dist . "\n" ; my $e ->{name}= $enemy ; $e ->{dist}= $dist ; push @enemies , $e ; } $min_e = $enemy ; $min_d = $dist ; print STDERR "enemies:" .$ #enemies . "\n"; for my $href ( @enemies ) { print STDERR "x:" . $href ->{name} . "\n" ; $name = $href ->{name}; $dist = $href ->{dist}; if ( $min_d > $dist ){ $min_d = $dist ; $min_e = $name ; } } print $min_e . "\n" ; # Write an action using print # To debug: print STDERR "Debug messages...\n"; #print "HotDroid\n"; # The name of the most threatening enemy (HotDroid is just one example) } |
'Programming > Contest' 카테고리의 다른 글
[codingame] The Descent (0) | 2014.12.13 |
---|---|
[codingame] Power of Thor (0) | 2014.12.13 |
=dovelet 블럭 색칠하기/paintblock (0) | 2014.08.19 |
=dovelet 퓨 즈/fuse (0) | 2014.08.19 |
=dovelet 손해 본 금액/business (0) | 2014.08.19 |
댓글