-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTriangle.cpp
More file actions
62 lines (54 loc) · 1.51 KB
/
Triangle.cpp
File metadata and controls
62 lines (54 loc) · 1.51 KB
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
60
// you can use includes, for example:
#include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A) {
// write your code in C++14 (g++ 6.2.0)
/*A.clear();
for(int k = 0;k < 100000;k++)
{
A.push_back(1);
}*/
sort(A.begin(), A.end());
int tri = 0;
for (vector<int>::const_iterator i = A.end()-1; i != A.begin()-1; --i)
{
//cout << "i " << *i;
if(*i < 0)
{
break;
}
for (vector<int>::const_iterator j = i-1; j != A.begin()-1; --j)
{
//cout << " j " << *j;
if(*j < 0)
{
break;
}
for (vector<int>::const_iterator k = j-1; k != A.begin()-1; --k)
{
long long int ij = 0;
ij = ij + *i;
ij = ij + *j;
//cout << " k " << *k;
if((*k < 0)||(*k > ij))
{
break;
}
long long int kj = 0;
kj = kj + *k;
kj = kj + *j;
long long int ki = 0;
ki = ki + *k;
ki = ki + *i;
//cout << "ki" << ki << endl;
if((kj > *i)&&(ij > *k)&&(ki > *j))
{
//cout << *k << " " << *j << " " << *i << endl;
return 1;
}
}
}
}
return 0;
}