結果

問題 No.22 括弧の対応
ユーザー 綾地寧々
提出日時 2015-05-02 18:45:09
言語 PHP
(843.2)
結果
WA  
実行時間 -
コード長 778 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 32,144 KB
実行使用メモリ 32,528 KB
最終ジャッジ日時 2024-07-05 17:29:22
合計ジャッジ時間 1,781 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 6 WA * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
list($length, $point) = explode(" ",trim(fgets(STDIN)));
$tree = 0;
$str = trim(fgets(STDIN));
if ( $str[$point-1] == '(' ) {
  $other = strlen(substr($str,0,$point-1));
  echo "other({$other}): ";
  $str = substr($str,$point-1);
  echo $str."\n";
  for ( $index=0; $index<strlen($str); $index++ ) {
    if ( $str[$index] == '(' ) {
      echo ++$tree;
    }
    else {
      echo $tree--;
    }
    if ( $tree == 0 ) {
      echo "index({$index}): ";
      echo $other + $index+1 . PHP_EOL;
      break;
    }
  }
}
else {
  $str = substr($str,0,$point);
  for ( $index=$point-1; $index>=0; $index-- ) {
    if ( $str[$index] == '(' ) {
      ++$tree;
    }
    else {
      $tree--;
    }
    if ( $tree == 0 ) {
      echo $index +1 . PHP_EOL;
      break;
    }
  }
}
0