-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhacker.cpp
60 lines (52 loc) · 1.36 KB
/
hacker.cpp
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
59
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int main(){
int i,i1,a0,q_i,T;
scanf("%d",&T);
for( a0 = 0; a0 < T; a0++){
int n,swap=0,j=0,k;
scanf("%d",&n);
int *q = (int*)malloc(sizeof(int) * n);
int *r= (int*)malloc(sizeof(int) * n);
for( q_i = 0; q_i < n; q_i++){
scanf("%d",&q[q_i]);
}
int flag=0;
for(i=0;i<n;i++)
{
for(k=0;k<j;k++)
if(r[k]==q[i])
{
flag=1;//set
break;
}
if(flag==1)
{
flag=0;
continue;
}
i1=i+1;
i1=abs(q[i]-i1);
if(i1!=0)
{
if(i1>2)
{
printf("Too chaotic\n");
exit(7);
}
++swap;
r[j++]=i+1;
}
}
printf("%d\n",swap);
/* for(k=0;k<j;k++)
printf("%d\n",r[k]);*/
// printf("%d=j",j);
}
return 0;
}