AcWing 2003. 找到牛!
原题链接
简单
作者:
虎头虎脑
,
2022-04-27 00:17:15
,
所有人可见
,
阅读 160
C++ 代码
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
string str;
cin >> str;
int res = 0, k = 0;
for(int i = 0; i < str.size(); ++ i)
{
if(str[i] == '(')
{
int cnt = 0, j = i;
while(j < str.size() && str[j] == '(')
cnt ++, ++ j;
i = j - 1;
if(cnt >= 2)
k += cnt - 1;
}
else if(str[i] == ')')
{
int cnt = 0, j = i;
while(j < str.size() && str[j] == ')')
cnt ++, ++ j;
i = j - 1;
if(cnt >= 2)
res += k * (cnt - 1);
}
}
cout << res << endl;
return 0;
}