0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-19 16:05:25 +00:00

A - Linear Keyboard

https://codeforces.com/problemset/submission/1607/136604168
This commit is contained in:
Baoshuo Ren 2021-11-23 21:28:52 +08:00 committed by Baoshuo Ren
parent d9ff28991c
commit 646a9848df
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

23
CodeForces/1607/A/A.cpp Normal file
View File

@ -0,0 +1,23 @@
#include <bits/stdc++.h>
using namespace std;
int t, ans;
string kbd, s;
map<char, int> key;
int main() {
cin >> t;
while (t--) {
ans = 0;
cin >> kbd >> s;
for (int i = 0; i < kbd.size(); i++) {
key[kbd[i]] = i;
}
for (int i = 1; i < s.size(); i++) {
ans += abs(key[s[i]] - key[s[i - 1]]);
}
cout << ans << endl;
}
return 0;
}