Codeforces 1607A. Linear Keyboard Solution
///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int t,i,sz,ans;
- cin>>t;
- while(t--)
- {
- ans=0;
- string s,t;
- map<char,int>mp;
- cin>>s;
- for(i=0; i<26; i++)
- {
- mp[s[i]]=i;
- }
- cin>>t;
- for(i=1; i<t.size(); i++)
- {
- ans+=abs(mp[t[i]]-mp[t[i-1]]);
- }
- cout<<ans<<endl;
- }
- }
No comments