Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- string s;
- cin >> s;
- int ans = (int) s.size();
- for (int i = 1; i < (int) s.size(); i++){
- string s1 = "", s2 = "";
- for (int j = 0; j < (int) s.size(); j++){
- if (j < i){
- s1 += s[j];
- } else {
- s2 += s[j];
- }
- }
- map<char, int> m1, m2;
- for (char c1 : s1){
- m1[c1]++;
- }
- for (char c2 : s2){
- m2[c2]++;
- }
- int res = 0;
- for (auto a : m1){
- if (m2.find(a.first) == m2.end()){
- res += a.second;
- }
- }
- for (auto b : m2){
- if (m1.find(b.first) == m1.end()){
- res += b.second;
- }
- }
- ans = min(ans, res);
- }
- cout << ans << endl;
- }
Add Comment
Please, Sign In to add comment