-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC.cpp
More file actions
53 lines (53 loc) · 1.19 KB
/
C.cpp
File metadata and controls
53 lines (53 loc) · 1.19 KB
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
#include "bits/stdc++.h"
using namespace std;
#define all(s) s.begin(),s.end()
int job_done(int n, string s1,string s2) {
int p1 = 0;
int cnt = 0;
string carry = "";
while (p1 < n )
{
// cout<<p1<<endl;
if (!carry.empty()) {
if (s1[p1] == '0' or s2[p1] == '0') {
cnt += 2;
p1++;
carry.clear();
} else {
p1++;
}
}
else if ((s1[p1] == '1' and s2[p1] == '0') or (s2[p1] == '1' and s1[p1] == '0')) {
cnt += 2;
p1++;
}
else if (s1[p1] == '0' and s2[p1] == '0') {
if(p1+1 < n and (s1[p1+1]=='1' and s2[p1+1]=='1')){
cnt+=2;
p1+=2;
}
else {
cnt += 1;
p1++;
}
}
else if (s1[p1] == '1' and s2[p1] == '1') {
carry += 1;
}
}
return cnt;
}
void C(){
int n;
cin>>n;
string s1,s2;cin>>s1>>s2;
int ans = job_done(n,s1,s2);
cout<<ans<<endl;
}
signed main() {
int t;
cin>>t;
while(t--){
C();
}
}