#include <cstdio> #include <cstring> #include <cstdlib> #include <map> using namespace std; map<long long, int> weight2count; char s[1<<25]; int sum; void build()//不一定要递归建树, [ 的数量减去 ] 数量就是结点的深度 { int len = strlen(s); int depth = 0; sum = 0; weight2count.clear(); for (int i = 0;i < len;i++) { switch (s[i]) { case '[': depth++;break; case ']': depth--;break; case ',': break; default: { long long w = s[i] - 48;//'0' int k; for (k = i + 1;s[k] >= '0'&&s[k] <= '9';k++) { w = w * 10 + s[k] - 48; } i = k - 1; sum++;weight2count[w << depth]++;//!以不同节点为基准若出现树的总质量相等,则以某个节点为基准另一个结点不需改变质量 } } } } int main(void) { int n; scanf("%d", &n); while (n--) { scanf("%s", s); build(); int max = 0; for (auto it = weight2count.begin();it != weight2count.end();it++) if (max < it->second)max = it->second; printf("%d ", sum-max); } return 0; }