Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
nearest
//Title of this code #include <iostream> #include <vector> using namespace std; vector<int> nearest(vector<int>& t) { vector<int> ret(t.size()); for (int i = 0; i < ret.size(); ++i) { int min = 999; int p; for (int j = i; j < t.size(); ++j) { if (t[j] - t[i] > 0 && t[j] - t[i] < min) { min = t[j] - t[i]; p = j; } } ret[i] = p; } return ret; } void print(vector<int>& t) { for (int i = 0; i < t.size(); ++i) cout << t[i] << " "; cout << endl; } int main() { vector<int> t; t.push_back(4); t.push_back(2); t.push_back(1); t.push_back(8); t.push_back(6); t.push_back(5); t.push_back(4); t.push_back(9); vector<int> t2 = nearest(t); print(t2); }
run
|
edit
|
history
|
help
0
Decimal to Binary
Test
DailyExchRate2
test111
remove dublicates from string using recursion
LALALALALALLLLAAA
sgfsfdgsfd
HeapDoubLinArr
Hi
in shorted array print without duplicate o/p array