a483: String Operation
Tags :
Accepted rate : 17人/24人 ( 71% ) [非即時]
評分方式:
Tolerant

最近更新 : 2021-11-28 21:21

Content

John is given a string S, and another string F with DISTNICT letters. He is asked to change letters (according to the rules below) in S in order that S only consists letters from F.

For every operation, he can change one letter in S into the one following it or preceding it in alphabetical order. For example, he can change "m" to either "n" or "l". Assume the letters are in a cylic order, meaning he can change the letter "a" to either "b" or "z".

Your job is to find out the the number of minimum operations N John needs to do.

 (Google Kick Start 2021 - Round H - Transform the String)

Input

The first line of input gives the number of test cases T with T cases following.

With every case, the first line contains the string S. Following by a line containing the string F with distinct letters.

All string inputs only consist of lowercase letters.

Output

For every test case, output only one line containing N.

Sample Input #1
2
aceg
c
pppp
p
Sample Output #1
8
0
Sample Input #2
3
pqrstuv
ow
abd
abd
aaaaaaaaaaaab
aceg
Sample Output #2
16
0
1
測資資訊:
記憶體限制: 48 MB
不公開 測資點#0 (2%): 0.1s , <1K
不公開 測資點#1 (3%): 0.1s , <1K
不公開 測資點#2 (25%): 0.2s , <1M
不公開 測資點#3 (70%): 10.0s , <10M
Hint :

Sample Input#1:
  For the first test case, "a" -> "b" -> "c" (2 operations), "c" (0 operation), "e" -> "d" -> "c" (2 operations), "g" -> "f" -> "e" -> "d" -> "c" (4 operations). Total N = 2 + 2 + 4 = 8
Sample Input#2:
  For the first test case, "p" -> "o" (1 op.), "q" -> "p" -> "o" (2 op.), "r" -> "q" -> "p" -> "o" (3 op.),  "s" -> "r" -> "q" -> "p" -> "o" OR "s" -> "t" -> "u" -> "v" -> "w" (both 4 op.), and so on (3 op. for "t", 2 op. for "u" and 1 op. for "v"). Total N = 1 + 2 + 3 + 4 + 3 + 2 + 1 = 16

Tags:
出處:
2021 Google Kick Start Round H [管理者:
0862410-0@g.... (顏俊偉-2023Leave)
]


ID User Problem Subject Hit Post Date
沒有發現任何「解題報告」