Created
May 28, 2021 23:44
-
-
Save joechai93/cb033c7dc698189855ae5c93b7d0b69b to your computer and use it in GitHub Desktop.
Missing value in ordered vector problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <vector> | |
#include <algorithm> | |
#include <numeric> | |
#include <cmath> | |
int main() | |
{ | |
std::vector<int> A = {1,3, 2,4,7,6}; | |
std::sort(A.begin(), A.end()); | |
std::vector<int> B(A.size()); | |
std::iota(B.begin(), B.end(), 1); | |
std::vector<int> C; | |
std::transform(A.begin(), A.end(), B.begin(), std::back_inserter(C), | |
[](double a, double b) { return fabs(a-b); }); | |
std::cout << (std::find(C.begin(), C.end(), 1))-C.begin() << std::endl; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment