diff --git a/2202/220219-CN.cpp b/2202/220219-CN.cpp new file mode 100644 index 0000000..7e06322 --- /dev/null +++ b/2202/220219-CN.cpp @@ -0,0 +1,29 @@ +#include +#include + +class Solution { +public: + static std::vector pancakeSort(std::vector& arr) { + std::vector ret; + int n = arr.size(); + ret.reserve(n << 1); + for (int i = n; i; --i) { + auto intervalLast = std::next(arr.begin(), i); + auto maxElement = std::max_element(arr.begin(), intervalLast); + ret.push_back(1 + std::distance(arr.begin(), maxElement)); + ret.push_back(i); + std::reverse(arr.begin(), std::next(maxElement)); + std::reverse(arr.begin(), intervalLast); + } + return ret; + } +}; + +int main() { + std::vector args = {1,2,3}; + auto ret = Solution::pancakeSort(args); + for (int i : ret) { + std::printf("%d ", i); + } + return 0; +} diff --git a/2202/CMakeLists.txt b/2202/CMakeLists.txt index 979b24e..3b9ceb3 100644 --- a/2202/CMakeLists.txt +++ b/2202/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2202) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2202 220218.cpp) +ADD_EXECUTABLE(2202 220219-CN.cpp)