📄 bracketmatching.cpp
字号:
//Bracket Matching Program
int main( )
/* Post: The program has notified the user of any bracket mismatch in the standard inputfile.
Uses: The classStack . */
{ Stack openings;
char symbol;
bool is_matched = true;
while(is_matched && (symbol=cin.get( )) != '\n')
{
if(symbol=='{' || symbol=='(' || symbol=='[')
openings.push(symbol);
if(symbol=='}' || symbol==')' || symbol==']')
{
if(openings.empty( ))
{ is_matched = false;
cout<<"Unmatched closing bracket"<<symbol<<" detected.\n";
}
else
{ char match;
openings.top(match);
openings.pop( );
is_matched=(symbol=='}' && match=='{')||(symbol==')' && match=='(')||(symbol==']' && match =='[');
if(!is_matched)
cout<<"Bad match "<<match<< symbol<<endl;
}
} //end_if(symbol=='}' ...
} //end_while
if(!openings.empty( )) cout<<"Unmatched opening bracket(s) detected.\n";
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -