diff --git a/cpp/2202/220223-CN.cpp b/cpp/2202/220223-CN.cpp new file mode 100644 index 0000000..4cee65e --- /dev/null +++ b/cpp/2202/220223-CN.cpp @@ -0,0 +1,25 @@ +#include +#include +#include + +class Solution { +public: + static std::string reverseOnlyLetters(std::string s) { + int L = 0, R = s.length() - 1; + for (; L < R && !std::isalpha(s[L]); ++L); + for (; R && !std::isalpha(s[R]); --R); + for (; L < R; ++L, --R) { + for (; L < R && !std::isalpha(s[L]); ++L); + for (; R && !std::isalpha(s[R]); --R); + if (L >= R) + break; + std::swap(s[L], s[R]); + } + return s; + } +}; + +int main() { + std::cout << Solution::reverseOnlyLetters("-"); + return 0; +} diff --git a/cpp/2202/CMakeLists.txt b/cpp/2202/CMakeLists.txt index 48623dc..7139825 100644 --- a/cpp/2202/CMakeLists.txt +++ b/cpp/2202/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2202) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2202 220222.cpp) +ADD_EXECUTABLE(2202 220223-CN.cpp)