#include<iostream>
#include<string>
#include<cassert>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;
const int MAXN = 24;
typedef long long LL;
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int t;
cin >> t;
string line;
map<LL, int> vCnt;
while (t-- > 0)
{
cin >> line;
vCnt.clear();
int sz = line.size();
int depth = 0, nodeCnt = 0;
for (int i = 0; i < sz; ++i)
{
char c = line[i];
if (c == '[')++depth;
else if (c == ']')--depth;
else if (isdigit(c))
{
LL v = c - '0';
int j;
for (j = i + 1; j < sz && isdigit(line[j]); ++j)
{
v *= 10;
v += line[j] - '0';
}
i = j - 1;
v <<= depth;
++vCnt[v];
++nodeCnt;
}
}
int K = -1;
for (const auto& p : vCnt)K = max(K, p.second);
assert(K > 0);
cout << (nodeCnt - K) << endl;
}
}
紫书UVa12166
最新推荐文章于 2024-06-21 17:14:10 发布