-
Notifications
You must be signed in to change notification settings - Fork 1
/
Broken_Telephone.c
53 lines (50 loc) · 1.15 KB
/
Broken_Telephone.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
52
53
#include<stdio.h>
int main()
{
long long int t,i;
scanf("%d",&t);
while(t--)
{
long long int n;
scanf("%lld",&n);
long long int count=0;
long long int present,prev,last_mismatch=-1;
scanf("%lld",&prev);
for(i=1;i<n;i++)
{
scanf("%lld",&present);
if(present!=prev)
{
if(count==0)
{
count += 2;
last_mismatch=i;
prev=present;
continue;
}
else
{
if((i-last_mismatch)>1)
{
count+=2;
prev=present;
continue;
}
else
{
count+=1;
prev=present;
continue;
}
}
}
else
{
prev=present;
continue;
}
}
printf("%lld\n",count);
}
return 0;
}