-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstickSort.c
36 lines (32 loc) · 866 Bytes
/
stickSort.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
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n, maxCirc = 0, Circ;
scanf("%d", &n);
int *sticks = malloc(sizeof(int) * n);
for (int i = 0; i < n; i++)
{
scanf("%d", sticks + i);
}
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
for (int k = j + 1; k < n; k++)
{
if (*(sticks + i) + *(sticks + j) > *(sticks + k) && *(sticks + i) + *(sticks + k) > *(sticks + j) && *(sticks + j) + *(sticks + k) > *(sticks + i))
{
Circ = *(sticks + i) + *(sticks + j) + *(sticks + k);
if (Circ > maxCirc)
{
maxCirc = Circ;
}
}
}
}
}
free(sticks);
printf("%d", maxCirc);
return 0;
}