<代码>//STL_stack。cpp:定义控制台应用程序的入口点。//STL栈栈
# include“stdafx.h”
# include & lt; iostream>
# include & lt; stack>
# include & lt; map>
# include & lt; string>
# include & lt; time.h>
使用名称空间性病;
multimap匹配;
multimaptrueMatch;
typedef pair:: iterator, multimap:: iterator>pairItr;
stack圣;
空白initMatch () {/*
\ (({}))
(2 2 2 0 0 1
[2 2 2 0 1 0
{2 2 2 1 0 0
}0 0 1 0 0 0
]0 1 0 0 0 0
)1 0 0 0 0 0
*/匹配。插入(make_pair (' (', ') '));
匹配。插入(make_pair (' (', ' '));
匹配。插入(make_pair (' (', ' {'));
匹配。插入(make_pair (' (', ' '));
匹配。插入(make_pair (' (', ') '));
匹配。插入(make_pair (' [', ' '));
匹配。插入(make_pair (' (', ' ('));
匹配。插入(make_pair (“[', ' {'));
匹配。插入(make_pair (' {', '} '));
匹配。插入(make_pair (' {', ' {'));
匹配。插入(make_pair (' {', ' '));
匹配。插入(make_pair (' {', ' ('));
match.insert (make_pair (‘)’,‘(’);
匹配。插入(make_pair ('] ', ' ('));
匹配。插入(make_pair ('} ', ' {'));/* - - - - - - - - - - - - - - - - - - - - - - - - - - - */trueMatch。插入(make_pair (' (', ') '));
trueMatch.insert (make_pair (‘)’,‘(’);
trueMatch。插入(make_pair ('] ', ' ('));
trueMatch。插入(make_pair (' (', ') '));
trueMatch。插入(make_pair (' {', '} '));
trueMatch。插入(make_pair ('} ', ' {'));
}
bool isMatch (char ch) {
如果(st.empty ()) {
st.push (ch);
返回true;
}
pairItr一对=match.equal_range (st.top ());
bool isExit=true;
(汽车itr=pair.first;itr !=pair.second; itr + +)
{
如果((* itr)。第二个==ch) {
isExit=false;
打破;
}
}
如果(isExit) {
返回错误;
}
如果(trueMatch.find (st.top ()) !=trueMatch.end (),,(* trueMatch.find (st.top ()))。第二个==ch) {
st.pop ();
返回true;
}
st.push (ch);
返回true;
}
int _tmain (int命令行参数个数,_TCHAR * argv [])
{
clock_t begin_clock_t=时钟();
initMatch ();//最糟糕情况匹配情况最后一位不匹配//string str="([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])([{}])[";
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null