-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCC-BINADD.cpp
More file actions
53 lines (46 loc) · 837 Bytes
/
CC-BINADD.cpp
File metadata and controls
53 lines (46 loc) · 837 Bytes
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>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){
int t;
cin >> t;
for(int k=0;k<t;k++){
string A,B,C;
cin >> A;
cin >> B;
C ="";
int len = max(A.length(),B.length())-min(A.length(),B.length());
int ans =0;
int mx=-1;
if(B.length()==1&&B[0]=='0'){
cout << 0 << "\n";
}else{
//a new string that'll contain zeroes upto diff
for(int i=0;i<len;i++){
C += "0";
}
//concatenate the string to the least of two
if(A.length()<B.length()){
A = C+A;
}else{
B = C+B;
}
for(int i=0;i<A.length();i++){
if(A[i]=='1'&&B[i]=='1'){
mx = max(mx,ans);
ans=0;
}
if(A[i]=='1'&&B[i]=='0'){
ans++;
}
if(A[i]=='0'&&B[i]=='1'){
ans++;
}
}
cout << mx+2 << "\n";
}
}
return 0;
}