Advertisement
Guest User

C

a guest
Sep 20th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1.     #define _CRT_SECURE_NO_WARNINGS
  2.      
  3.     #include <iostream>
  4.     #include <algorithm>
  5.     #include <cmath>
  6.     #include <string>
  7.     #include <vector>
  8.     #include <map>
  9.     #include <set>
  10.     #include <queue>
  11.     #include <assert.h>
  12.      
  13.     using namespace std;
  14.      
  15.     #define ll long long
  16.     #define ull unsigned long long
  17.     const ll INF = 1e18;
  18.     const double PI = acos(-1.0);
  19.      
  20.      
  21.      
  22.     int main()
  23.     {
  24.         //freopen("INPUT.TXT", "r", stdin);
  25.         //freopen("OUTPUT.TXT", "w", stdout);
  26.         ios::sync_with_stdio(false);
  27.      
  28.         int n;
  29.         cin >> n;
  30.         string s;
  31.         cin >> s;
  32.      
  33.         int cnt0 = 0, cnt1 = 0;
  34.         for (int i = 0; i < n; i++)
  35.         {
  36.             if (s[i] == '0')
  37.                 cnt0++;
  38.             else
  39.                 cnt1++;
  40.         }
  41.      
  42.         int mini = min(cnt0, cnt1);
  43.         int res = n - mini * 2;
  44.         cout << res;
  45.      
  46.         //system("pause");
  47.         return 0;
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement