Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
triplets from vector
//Title of this code #include <iostream> #include <vector> #include <tuple> using namespace std; vector<tuple<int,int,int>> getTriplets(vector<int>& t) { vector<tuple<int,int,int>> ret; for (int i = 0; i < t.size(); ++i) for (int j = i + 1; j < t.size(); ++j) for (int k = j + 1; k < t.size(); ++k) if (t[i] < t[j] && t[j] < t[k]) { tuple<int, int, int> triplet(i,j,k); ret.push_back(triplet); } return ret; } void print(vector<int>& t, vector<tuple<int,int,int>>& r) { for (int i = 0; i < r.size(); ++i) { cout << t[get<0>(r[i])] << " " << t[get<1>(r[i])] << " " << t[get<2>(r[i])] << " ---> "; cout << get<0>(r[i]) << " " << get<1>(r[i]) << " " << get<2>(r[i]) << endl; } } int main() { vector<int> t; t.push_back(10); t.push_back(2); t.push_back(6); t.push_back(16); t.push_back(30); t.push_back(13); t.push_back(2); t.push_back(67); vector<tuple<int,int,int>> r = getTriplets(t); print(t, r); }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
pointer array of functions
Merge problem
max subsequence of array
aju
Palindromo
Vector+Memory_Adv_C++_Tutorial
Perf measurement
Compatibilità
TREE - path from root to leaf with given sum
copy_if c++98
Please log in to post a comment.