Bamboo and the Ancient Spell

时间限制: 1000 ms 内存限制: 65536 kb
总通过人数: 0 总提交人数: 0

Problem description

The Hogwarts has set up a new course recently, giving you the ancient spells and requiring you to translate them into the modern ones. Every two ancient spells encode one modern spell.

Wizards and witches just point the ancient spells with the magic wands and speak loudly "THE LONGEST COMMON SUBSEQUENCE !", and they'll get the modern spell required:)

Ok, stop trying this muggles...Though we can't get the answers as quickly as they do, we can still decode them by coding :)

So Bamboo will give you a lot of ancient spells( two in a group),and hope you just return the LENGTH of the modern spell.

Attention please! The ancient spells may include strange characters '#' and '?'. They are too old to know their exact meanings, so we can just think that '#'s can not match any character while finding the answer, but '?' can match any character in the other ancient spell except '#'.

Input

The input file consists of several test cases.

Each test case includes 2 lines, one ancient spell per line.

The length of per ancient spell will less than 100 characters,and all characters are in upper case.

Output

For each case, output one line: the length of the modern spell.

sample input

ABCDE
ZBD
AC#EB
C#BFG
ACE#?
KIKI#A
???
?#?

Sample output

2
2
1
2

A TIP

emmmm, Can you guess what 'spell' means here? And what about the modern spells? Pay attention to what wizards and witches say when they use magic.

Another TIP

In case 2, '#' can not match any character, just like it doesn't exist, so the modern spell is "CB".

In case 3, '?' can match any character except '#', which means '?' can be seen as ‘A~Z' and '?' of course.

相关推荐