-
Notifications
You must be signed in to change notification settings - Fork 147
/
HOWMANYMAX.c
51 lines (42 loc) · 934 Bytes
/
HOWMANYMAX.c
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
// https://www.codechef.com/problems/HOWMANYMAX
#include <stdio.h>
int main()
{
int t;
scanf("%d", &t);
for (int i = 0; i < t; i++)
{
int n;
scanf("%d", &n);
int count = 0;
char str[n - 1];
scanf("%s", str);
if (str[0] == '0')
{
for (int i = 0; i < n - 1; i++)
{
if (str[i] == '0' && str[i + 1] == '1')
{
count++;
}
}
if (str[n - 2] == '0')
{
count++;
}
printf("%d\n", count);
}
if (str[0] == '1')
{
for (int i = 0; i < n - 1; i++)
{
if (str[i] == '1' && str[i + 1] == '0')
{
count++;
}
}
printf("%d\n", count+1);
}
}
return 0;
}