【ABC453ABC】

関連記事

1. A – Trimo

長さ NN の文字列 SS が与えられます。SS のうち先頭に連続する o をすべて取り除いた文字列を出力してください。

なお、SS 中のすべての文字が o である場合は空文字列を出力してください。

入力は以下の形式で標準入力から与えられる。

N
S

答えを出力せよ。

A – Trimo

例 1

7
ooparts

ooparts のうち先頭に連続する o をすべて取り除くと parts となります。

parts

例 2

6
abcooo

先頭の文字が o でない場合もあります。

abcooo

1.1. 回答

素直に文字列の先頭が文字に合致する間進むことにしました。

(defun solve (n s)
  (declare (type fixnum n)
	   (type string s)
	   (ignore n))
  (subseq s (length-first-char s #\o)))

(defun length-first-char (str ch)
  (declare (type string str)
	   (type character ch))
  (loop for i from 0
	for ch2 across str
	while (eql ch2 ch)
	finally (return i)))

(defun main ()
  (let* ((n (read))
	 (s (read-line)))
    (princ (solve n s))))

#-swank
(main)Code language: Lisp (lisp)
1.1. 回答

2.