-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCodeChefEliminationRoundProgram
More file actions
91 lines (75 loc) · 2.94 KB
/
CodeChefEliminationRoundProgram
File metadata and controls
91 lines (75 loc) · 2.94 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
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
#include <iostream>
using namespace std;
int main(){
int q;
cin>>q;
int num=0;
for(int i=0;i<q;i++){
int n;
cin>>n;
num=0;
char a[2][n];
for(int j=0;j<2;j++){
for(int k=0;k<n;k++){
cin>>a[j][k];
}
}
char c[n];
int z=0;
for(int k=0;k<n;k++){
for(int j=0;j<2;j++){
if(a[j][k]=='*'){
c[z]='*';
break;
}
}
z++;
}
// for(int j=0;j<n;j++)
// cout<<c[j]<<" ";
// cout<<endl;
int temp=0;
for(int j=0;j<n;j++){
if(c[j]=='*')
temp++;
}
if(temp>0)
num=temp-1;
for(int j=0;j<n;j++){
if(a[0][j]=='*' && a[1][j]=='*'){
num++;
break;
}
}
cout<<num;
}
return 0;
}
PROGRAM EXPLANATION
Snakeland is a well organised city. The houses of the city are organised in an orderly rectangular fashion with dimensions 2 * n, i.e. there are total two rows and n columns. The house in the i-th row and j-th column is also said to be the house at coordinates (i, j). Some of the houses are occupied by snakes, while the others are empty. You are given this information through an array s of dimension 2 * n, where, if s[i][j] = '*', it denotes that there is a snake in the house at coordinates (i, j), and if s[i][j] = '.', it denotes that the house is empty.
These snakes are planning a coup against a mongoose who controls their city from outside. So, they are trying their best to meet with other snakes and spread information about the date of the coup. For spreading this information, they can just hiss from their house and usually their hiss is so loud that it will be heard in all the cells except if there is a soundproof fence built that cuts the voice. Note that the external borders of Snakeland are already built of soundproof material. The mongoose got to know about the plan, and he wants to construct sound proof fences along the borders of the houses so that no two people should be able to communicate with each other. The fence can be either vertical or horizontal. Each fence can be of any length, but the mongoose wants to minimize the number of fences to be built. Find out the minimum number of fences that the mongoose should build.
Input
The first line of the input contains an integer T denoting number of test cases. The descriptions of the T test cases follow.
The first line of each test case contains a single integer, n.
Each of the next two lines contains n characters denoting the first and the second rows of Snakeland respectively.
Output
For each test case, output a single integer corresponding to the minimum number of fences that the mongoose needs to build.
Constraints
1 ≤ T ≤ 10
1 ≤ n ≤ 105
Example
Input
3
2
**
**
3
***
*..
3
*..
.*.
Output
2
3
1