-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path132_pattern.cpp
More file actions
51 lines (48 loc) · 1.02 KB
/
132_pattern.cpp
File metadata and controls
51 lines (48 loc) · 1.02 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
#include <stdc++.h>
using namespace std;
// 1,2,3,4
// 1 3 2
bool find132pattern(vector<int> &nums)
{
int x = nums.size() - 2;
for (int i = 0; i < x; i++)
{
// cout << "corrected" << endl;
for (int j = i; j < nums.size(); j++)
{
// cout << "corrected" << endl;
if (nums.at(i) < nums.at(j))
{
for (int k = j; k < nums.size(); k++)
{
if (nums.at(i) < nums.at(k) && nums.at(j) > nums.at(k))
{
cout << nums.at(i) << " " << nums.at(j) << " " << nums.at(k) << endl;
return true;
}
}
}
}
}
return false;
}
int main()
{
vector<int> v;
int a, x;
cin >> a;
for (int i = 0; i < a; i++)
{
cin >> x;
v.push_back(x);
}
if (find132pattern(v))
{
cout << "found" << endl;
}
else
{
cout << "Not found" << endl;
}
return 0;
}