アルゴリズムのアウトプット
ということで、
レッドコーダーが教える、競プロ・AtCoder上達のガイドライン【中級編:目指せ水色コーダー!】@e869120さん
AtCoder で水色コーダー、つまりレーティング 1200 を少ない問題数で達成するために、茶色コーダー・緑コーダーにとって適切な教育的良問を 100 問集めました。
こちらの記事の初中級者が解くべき過去問精選 100 問
をPHPで解いていきます。
<?php
$wordArr = str_split(trim(fgets(STDIN)));
$num = count($wordArr);
$max = 0;
$count = 0;
$acgt = ['A', 'C', 'G', 'T'];
for ($i = 0; $i < $num; $i++) {
if (in_array($wordArr[$i], $acgt)) {
$count++;
$max = max($count, $max);
} else {
$count = 0;
}
}
echo $max;
文字列を配列化し順番に該当する文字かどうか判定。
連続している間は足し上げていき、対象出ない場合はcountをリセットする問題。