c++括號匹配

括號匹配是棧最典型的應用了。ios 思路很簡單,就是遇到一個左括號就壓棧,遇到一個右括號就彈棧,看是否匹配就行了。最後檢查下棧是否爲空就好了。code #include <iostream> #include <stack> #include <string> bool paren(const std::string &str) { std::stack<char> s; for (auto
相關文章
相關標籤/搜索