-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcdd1.cpp
More file actions
58 lines (57 loc) · 799 Bytes
/
cdd1.cpp
File metadata and controls
58 lines (57 loc) · 799 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
int arr[n],a,p=1,time=0,f=0,count=0,count1=0;
for(int i=0;i<n;i++)
{
scanf("%d",&arr[i]);
if(arr[i]==1)
count++;
else
count1++;
}
if(count==n || count1==n)
printf("0\n");
else
{
while(1)
{
f=0;
for(int i=0;i<count;i++)
{
if(arr[i]!=1)
{
f=1;
break;
}
}
if(f==0)
break;
time++;
for(int i=0;i<n-1;i++)
{
if(arr[i]==0&&arr[i+1]==1)
{
a = arr[i+1];
arr[i+1] = arr[i];
arr[i] = a;
i++;
}
}
//for(int i=0;i<n;i++)
// printf("%d ",arr[i]);
//cout<<endl;
}
//cout<<endl;
printf("%d\n",time);
}
}
return 0;
}