mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 03:31:59 +00:00
A - Linear Keyboard
https://codeforces.com/problemset/submission/1607/136604168
This commit is contained in:
parent
d9ff28991c
commit
646a9848df
23
CodeForces/1607/A/A.cpp
Normal file
23
CodeForces/1607/A/A.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user