forked from Mohammed-Shoaib/Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathE0030.cpp
More file actions
41 lines (37 loc) · 684 Bytes
/
E0030.cpp
File metadata and controls
41 lines (37 loc) · 684 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
// Problem Code: LEBOMBS
#include <iostream>
#include <string>
using namespace std;
int littleElephantAndBombs(string S){
int exploded = 0;
bool first = true;
if(S[0] == '1'){
exploded += (S.length() == 1) ? 1 : 2;
first = false;
}
for(int i=1 ; i<S.length()-1 ; i++){
if(first && S[i] == '1'){
exploded += 3;
first = false;
}else if(S[i] == '1')
exploded++;
else{
if(!first && S[i+1] == '1')
exploded--;
first = true;
}
}
if(first && S[S.length()-1] == '1')
exploded += 2;
return S.size() - exploded;
}
int main(){
int T, N;
string S;
cin >> T;
while(T--){
cin >> N >> S;
cout << littleElephantAndBombs(S) << endl;
}
return 0;
}