Tuesday, January 21, 2014

codechef LEBOMBS - "little elephant and bombs" solution

codechef LEBOMBS - "little elephant and bombs": http://www.codechef.com/problems/LEBOMBS

codechef LEBOMBS - "little elephant and bombs" solution: http://ideone.com/640R3v

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
int t, n, cnt, a[1005];
char c[1005];
scanf("%d", &t);
while(t--) {
scanf("%d", &n);
cnt=0;
memset(a, 0, sizeof(a));
scanf("%s", c);
for(int i=0; i<strlen(c); i++) {
if(c[i]=='0' && i==0) a[i]=0;
else if(c[i]=='1' && i==0) a[i]=a[i+1]=1;
else if(c[i]=='1' && i==n-1) a[i-1]=a[i]=1;
else if(c[i]=='1') a[i-1]=a[i]=a[i+1]=1;
}
for(int i=0; i<n; i++) if(a[i]==0) cnt++;
printf("%d\n", cnt);
}
return 0;
}

No comments:

Post a Comment