-
Notifications
You must be signed in to change notification settings - Fork 1
/
zad9_ms.c
49 lines (45 loc) · 1.01 KB
/
zad9_ms.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
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include <stdlib.h>
// -1 if a+b<c, 0 on equality, 1 otherwise
int triangle_inequality(int a, int b, int c)
{
int s = a + b;
if (s < c)
return -1;
if (s == c)
return 0;
return 1;
}
int trojki(int size, int tab[])
{
int c = 0;
for (int ai = 0; ai < size; ai++)
{
for (int bi = ai + 1; bi < size; bi++)
{
for (int ci = bi + 1; ci < size; ci++)
{
int status = triangle_inequality(tab[ai], tab[bi], tab[ci]);
if (status <= 0)
{
if (status == 0)
ci++;
c += size - ci;
break;
}
}
}
}
return c;
}
int main()
{
int n;
if(!scanf("%d", &n)) printf("wrong input");
int *t = (int *)malloc((size_t)n * sizeof(int));
for (int i = 0; i < n; i++)
{
if(!scanf("%d", &t[i])) printf("wrong input");
}
printf("%d\n", trojki(n, t));
}