标签:|| dex ace return begin using 匹配 top namespace
#include <iostream> using namespace std; #include <string> bool ShiPiPei(const char* test) { string s; char str[100]; int topStackIndex = 0; s.assign(test); for (string::iterator it = s.begin(); it != s.end(); it++){ if ((*it) == ‘(‘ || (*it) == ‘[‘) { str[topStackIndex++]=(*it); } else if ((*it) == ‘)‘) { if (str[--topStackIndex] == ‘(‘) { } else { //cout << "不匹配!" << endl; return false; } } else if ((*it) == ‘]‘) { if (str[--topStackIndex] == ‘[‘) { } else { //cout << "不匹配!" << endl; return false; } } } //cout << "匹配"; return true; } int main() { if (ShiPiPei("([)]")) { cout << "匹配!" << endl; } else { cout<<"不匹配!" << endl; } }
标签:|| dex ace return begin using 匹配 top namespace
原文地址:https://www.cnblogs.com/likeghee/p/10177103.html