Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void solve()
- {
- string s1, s2;
- cin >> s1 >> s2;
- map<int, int> mp1, mp2;
- for (int i = 0; i < s1.length(); i++)
- {
- mp1[s1[i]]++;
- }
- for (int i = 0; i < s2.length(); i++)
- {
- mp2[s2[i]]++;
- }
- for (char ch = 'a'; ch <= 'z'; ch++)
- {
- int x = min(mp1[ch], mp2[ch]);
- mp1[ch] -= x;
- mp2[ch] -= x;
- }
- int ans = 0;
- for (char ch = 'a'; ch <= 'z'; ch++)
- {
- char curr = ch;
- char prev;
- if (curr == 'a')
- prev = 'z';
- else
- prev = curr - 1;
- if (mp2[curr])
- {
- if (mp1[prev] >= mp2[curr])
- {
- ans += mp2[curr];
- }
- else
- {
- ans += mp1[prev];
- ans += 2 * (mp2[curr] - mp1[prev]);
- }
- }
- }
- cout << ans << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment