3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【電脳少女 プログラミング2088 Cランク】 ネオン街のクラブ PowerShellによる

Last updated at Posted at 2025-02-18

今回は、こちらのプログラミングゲームの解答コードを投稿しよう!の公式イベントの記事になります。

具体的には、paizaの新作プログラミングゲーム「電脳少女プログラミング2088 ─壊レタ君を再構築─」の「ネオン街のクラブ
」という問題をPowerShell 5.1で解いてみたいと思います。

問題

答え


$n = read-host
$s = read-host

$unique = ""

foreach ($char in $s.ToCharArray()) {
    if (-not $unique.Contains($char)) {
        $unique += $char
    }
}

Write-Output $unique.Length

これは最初の2行で入力値を受け取り
ループして重複を除外
最後に除外した文字列の長さを出力しています。

ポイントは
foreach ($char in $s.ToCharArray()) {
ここで$s.ToCharArray()こうすると文字列が格納されている$sの中身を1文字づつ取り出せます。
取り出された文字列は$charに代入され、
ループの中のIF文で変数$uniqueに含まれるかどうか判定して、含まれていなかったら$uniqueに継ぎ足しています。
最後に$uniqueの長さを出力。

最後に

このようなイベントをPowerShellでやる人は珍しいと思います。
PowerShellに興味を持った方は応援してね

下のリンク先でも記事を書いています

3
2
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?