-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.cpp
56 lines (47 loc) · 886 Bytes
/
1.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
#include<stdio.h>
int bubSort(int arr[],int length)
{
int temp;
for(int i=length-1;i>=0;i--)
{
for(int k=0;k<i;k++)
{
if(arr[k]>arr[k+1])
{
temp=arr[k+1];
arr[k+1]=arr[k];
arr[k]=temp;
}
}
}
return 0;
}
int main()
{
int N,path[100];
scanf("%d",&N);
for(int k=0;k<N;k++)
{
int Case[100],n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&Case[i]);
}
bubSort(Case,n);
path[k]=0;
for(int m=0;m<n-1;m++)
{
int temp=((Case[m])-(Case[m+1]));
if(temp<0)
temp*=-1;
path[k]+=temp;
}
printf("%d\n",path[k]);
}
/*for(int m=0;m<N;m++)
{
printf("%d\n",path[m]);
}*/
return 0;
}