fork(1) download
  1. #include <cstdio>
  2. #include <cstring>
  3. using namespace std;
  4. int main(void)
  5. {
  6. int t, n, i;
  7. scanf ("%d", &t);
  8. for (t; t > 0; --t)
  9. {
  10. int count = 0;
  11. scanf ("%d", &n);
  12. char str[1001] = {'\0'};
  13. scanf ("%s", str);
  14. if (n == 1)
  15. {
  16. ;
  17. }
  18. else
  19. {
  20. for (i = 1; i < (n-1); ++i)
  21. {
  22. if (str[i] == '1')
  23. {
  24. str[i] = 'a';
  25. str[i-1] = 'a';
  26. str[i+1] = 'a';
  27. }
  28. }
  29. }
  30. if (str[0] == '1')
  31. {
  32. str[0] = 'a';
  33. str[1] = 'a';
  34. }
  35. if (str[n-1] == '1')
  36. {
  37. str[n-1] = 'a';
  38. str[n-2] = 'a';
  39. }
  40. for (i = 0; i < n; ++i)
  41. {
  42. if (str[i] == '0')
  43. ++count;
  44. }
  45. printf ("%d\n", count);
  46. }
  47. return 0;
  48. }
Success #stdin #stdout 0s 3344KB
stdin
2
1
0
2
00
stdout
1
2