1. 题目
示例输入
((a,b,(c,(d,e),f)),g)
示例输出
4
4
2. 代码
先写个不符合题目要求的简单代码完成作业,,,有时间再按要求填坑。
#include <iostream>
#include <string>
using namespace std;
// 用一个极其不符合题意的简单方法
int main(){
string str;
int tmp = 0, max = 0;
cin >> str;
int len = str.length();
for(int i=0; i<len; i++){
if(str[i] == '('){
tmp++;
}
if(str[i] == ')'){
if(tmp > max){
max = tmp;
}
tmp--;
}
}
cout << max << endl << max;
return 0;
}