#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
/*
求广义表的深度(括号匹配)
示例:
输入:(c,((d,e),f),h)
输出:3
*/
int main(){
int total = 0; //总层数
int n = 0; //当前所处层数
string str;
while(1){
getline(cin, str);
for(int i=0; i<str.length(); i++){
if(str[i] == '('){
n++;
if(n > total)total = n;
}if(str[i] == ')'){
n--;
}
}
cout << total << endl;
}
return 0;
}
2014北理上机-广义表深度
最新推荐文章于 2021-07-27 19:11:00 发布