Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Find Triplets or Duplets that the sum is multiplie of three
//Title of this code #include <iostream> #include <vector> #include <tuple> using namespace std; void getTriplets(vector<int>& t) { vector<tuple<int,int,int>> triplets; vector<tuple<int,int>> duplets; for (int i = 0; i < t.size(); ++i) { for (int j = i + 1; j < t.size(); ++j) { if ((t[i] + t[j]) % 3 == 0) { tuple<int, int> duplet(i,j); duplets.push_back(duplet); } for (int k = j + 1; k < t.size(); ++k) { if ((t[i] + t[j] + t[k]) % 3 == 0) { tuple<int, int, int> triplet(i, j, k); triplets.push_back(triplet); } } } } for (int i = 0; i < duplets.size(); ++i) { cout << t[get<0>(duplets[i])] << " " << t[get<1>(duplets[i])] << endl; } for (int i = 0; i < triplets.size(); ++i) { cout << t[get<0>(triplets[i])] << " " << t[get<1>(triplets[i])] << " " << t[get<2>(triplets[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(4); t.push_back(67); getTriplets(t); }
run
|
edit
|
history
|
help
0
Radix sort
QuickDoubly
dsadasdsa
Meeting_Leandro
Matrix
code
Parser + Str2Int
remove dublicates from string using recursion
¡Arriba, Papalotes, Arriba!
input