aboutsummaryrefslogtreecommitdiff
path: root/41
diff options
context:
space:
mode:
Diffstat (limited to '41')
-rw-r--r--41/balance.cc39
1 files changed, 39 insertions, 0 deletions
diff --git a/41/balance.cc b/41/balance.cc
new file mode 100644
index 0000000..b379f0d
--- /dev/null
+++ b/41/balance.cc
@@ -0,0 +1,39 @@
+#include <bits/stdc++.h>
+using namespace std;
+
+bool is_balance(int a) {
+ int one_num = 0;
+ int zero_num = 0;
+ while (a != 0)
+ {
+ if ((a & 1) == 0) {
+ zero_num++;
+ } else {
+ one_num++;
+ }
+ a = a >> 1;
+ }
+ if (one_num == zero_num) {
+ return true;
+ }
+ return false;
+}
+
+int main() {
+ ios::sync_with_stdio(false);
+ cin.tie(nullptr);
+ int n;
+ cin >> n;
+ vector<int> a(n);
+ for (int i = 0; i < n; ++i) {
+ cin >> a[i];
+ }
+ int cnt = 0;
+ for (int i = 0; i < n; ++i) {
+ if (is_balance(a[i])) {
+ cnt++;
+ }
+ }
+ cout << cnt << endl;
+ return 0;
+} \ No newline at end of file