forked from ajeetshah/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstone.c
More file actions
40 lines (36 loc) · 748 Bytes
/
stone.c
File metadata and controls
40 lines (36 loc) · 748 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
#include<stdio.h>
#define SIZE 20
int main(){
int i;
int j;
int W[SIZE];
int t;
int n;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&W[i]);
}
for(i=0;i<n;i++){
for(j=i+1;j<n;j++){
if(W[i]>W[j]){
t = W[i];
W[i] = W[j];
W[j] = t;
}
}
}
t = W[n-1];
for(i=n-1;i>0;i--){
if (t>0){
t = t - W[i-1];
}
else if (t<0){
t = W[i-1] + t;
}
else {
t = W[i-1];
}
}
printf("%d",t);
return 0;
}