-
Notifications
You must be signed in to change notification settings - Fork 0
/
Digit Game.cpp
104 lines (80 loc) · 1.99 KB
/
Digit Game.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Problem: A. Digit Game
// Contest: Codeforces - Codeforces Round #671 (Div. 2)
// URL: https://codeforces.com/contest/1419/problem/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define ll long long int
#define vi vector<int>
#define vii vector<int, int>
#define vc vector<char>
#define vl vector<ll>
#define mod 1000000007
#define INF 1000000009
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
t = 1;
cin >> t;
while(t--) {
int n;
cin >> n;
string s;
cin >> s;
int total_odd = 0, total_even = 0;
int odd_on_even = 0, even_on_odd = 0;
int dig;
for(int i = 0 ; i < n; i++) {
dig = s[i] - '0';
if(dig % 2 != 0){
total_odd++;
if((i + 1 )% 2 == 0) {
odd_on_even++;
}
}
else {
total_even++;
if((i+1) % 2 != 0) {
even_on_odd++;
}
}
}
//cout << total_odd << " " << total_even << " ";
while(total_odd != 0 and total_even != 0) {
// cout << odd_on_even << " " << even_on_odd << " ";
if(even_on_odd > 0) {
even_on_odd--;
total_even--;
}
else if(even_on_odd == 0) {
total_odd--;
}
if(total_even == 0 or total_odd == 0) {
break;
}
if(odd_on_even > 0) {
odd_on_even--;
total_odd--;
}
else if(odd_on_even == 0) {
total_even--;
}
}
if(total_odd > 0) {
cout << "1\n";
}
else {
cout << "2\n";
}
}
return 0;
}