CONSTRUCT STRING

Xem dạng PDF

Gửi bài giải

Điểm: 1,00 (OI)
Giới hạn thời gian: 1.0s
Giới hạn bộ nhớ: 256M
Input: stdin
Output: stdout

Nguồn bài:
Hà Minh Ngọc
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch

A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters. For example: abc is a subsequence of abbac.

You are given two strings ~s~ and ~t~ consisting of only lowercase English letters. Find the minimum number of characters that need to be appended to the end of ~s~ so that ~t~ becomes a subsequence of ~s~.

Input

  • The first line is the string ~s~ ~(0 ≤ |s| ≤ 10^5)~.

  • The second line is the string ~t~ ~(0 ≤ |t| ≤ 10^5)~.

  • Both strings contain only lowercase characters.

Output

  • The minimum number of characters that need to be appended to the end of ~s~ so that ~t~ becomes a subsequence of ~s~.

Sample Input 1

abbac
abc

Sample Output 1

0

Sample Input 2

baac
abc

Sample Output 2

2

Sample Input 3

aaaaa
abc

Sample Output 3

2

Sample Input 4

abcabc
cba

Sample Output 4

1

Notes:

  • In the first sample, ~t~ is already a subsequence of ~s~, so there is no need to add any characters.

  • In the second and the third samples, bc should be added to ~s~

  • In last sample, a should to be added to ~s~.


Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.