diff --git a/cpp/2203/220317.cpp b/cpp/2203/220317.cpp new file mode 100644 index 0000000..0bc25eb --- /dev/null +++ b/cpp/2203/220317.cpp @@ -0,0 +1,23 @@ +#include +#include + +class Solution { +public: + static int scoreOfParentheses(const std::string& s) { + int stack[30], top = -1, ret = 0; + for (char ch : s) { + if (ch == '(') { + stack[++top] = 0; + } else { // ch == ')' + *(top ? &stack[top - 1] : &ret) += (stack[top] ? stack[top] << 1 : 1); + --top; + } + } + return ret; + } +}; + +int main() { + std::cout << Solution::scoreOfParentheses("((())())"); + return 0; +} diff --git a/cpp/2203/CMakeLists.txt b/cpp/2203/CMakeLists.txt index 30eaf5e..44a1aae 100644 --- a/cpp/2203/CMakeLists.txt +++ b/cpp/2203/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2203) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2203 220316-CN.cpp) +ADD_EXECUTABLE(2203 220317.cpp)