結果
問題 | No.495 (^^*) Easy |
ユーザー |
![]() |
提出日時 | 2024-10-10 00:28:51 |
言語 | Common Lisp (sbcl 2.5.0) |
結果 |
AC
|
実行時間 | 17 ms / 2,000 ms |
コード長 | 1,251 bytes |
コンパイル時間 | 456 ms |
コンパイル使用メモリ | 26,880 KB |
実行使用メモリ | 22,784 KB |
最終ジャッジ日時 | 2024-10-10 00:28:52 |
合計ジャッジ時間 | 1,360 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 7 |
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 10 OCT 2024 12:28:51 AM): ; wrote /home/judge/data/code/Main.fasl ; compilation finished in 0:00:00.067
ソースコード
; 左向きは ^* 、右向きは *^ が特徴的な量なのでこの数を数える; 文字列の中の文字列パターンの数を数える関数; (count-pattern-string "*^" "(^^*)(^^*)(*^^)(*^^)(^^*)(*^^)(*^^)#"); => 4; (count-pattern-string "^*" "(^^*)(^^*)(*^^)(*^^)(^^*)(*^^)(*^^)#"); => 3(defun count-pattern-string (pattern str)(let ((count 0) ; str に表れる pattern の個数(pos 0)) ; str に表れる pattern の位置(loop; str 中で pattern が表れた位置を更新しながら繰り返す(setq pos; search sequence-1 sequence-2 &key from-end test test-not key start1 start2 end1 end2 ⇒ position; sequence-2 の部分列と sequence-1 がマッチする場所を探す; start2 キーワードは sequence-2 のスタート位置を設定するために使う(search pattern str :start2 pos))(if pos(progn(incf count)(setq pos (1+ pos)))(return count)))))(defun main (&rest argv)(declare (ignorable argv))(let* ((s (read-line))(l (count-pattern-string "^*" s))(r (count-pattern-string "*^" s)))(princ l)(write-char #\space)(princ r)(terpri)))(main)