tsypko

C

Jun 2nd, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.    
  6.     string s;
  7.     cin >> s;
  8.    
  9.     int ans = (int) s.size();
  10.    
  11.     for (int i = 1; i < (int) s.size(); i++){
  12.         string s1 = "", s2 = "";
  13.         for (int j = 0; j < (int) s.size(); j++){
  14.             if (j < i){
  15.                 s1 += s[j];
  16.             } else {
  17.                 s2 += s[j];
  18.             }
  19.         }
  20.         map<char, int> m1, m2;
  21.         for (char c1 : s1){
  22.             m1[c1]++;
  23.         }
  24.         for (char c2 : s2){
  25.             m2[c2]++;
  26.         }
  27.         int res = 0;
  28.         for (auto a : m1){
  29.             if (m2.find(a.first) == m2.end()){
  30.                 res += a.second;
  31.             }
  32.         }
  33.         for (auto b : m2){
  34.             if (m1.find(b.first) == m1.end()){
  35.                 res += b.second;
  36.             }
  37.         }
  38.         ans = min(ans, res);
  39.     }
  40.     cout << ans << endl;
  41.    
  42. }
Add Comment
Please, Sign In to add comment