0
0

More than 3 years have passed since last update.

【PHP】初中級者が解くべき過去問精選 100 問を解いてみた【3問目/100】

Last updated at Posted at 2021-01-23

アルゴリズムのアウトプット

ということで、
レッドコーダーが教える、競プロ・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をリセットする問題。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0