标签:
#include"iostream"
#include"cstdio"
#include"cstring"
#include"map"
using namespace std;
map<long long,int>book;
int sum;
string a;
void biaoji(int depth,int b,int e)
{
if(a[b]==‘[‘)
{
int p=0;
for(int i=b+1;i<e;i++)
{
if(a[i]==‘[‘) p++;
if(a[i]==‘]‘) p--;
if(p==0&&a[i]==‘,‘)
{
biaoji(depth+1,b+1,i-1);
biaoji(depth+1,i+1,e-1);
}
}
}
else
{
long long w=0;
for(int j=b;j<=e;j++) w=w*10+a[j]-‘0‘;
sum++;
// cout<<w<<endl;
book[w<<depth]++;
}
}
int main()
{
int T;
cin>>T;
// getchar();
while(T--)
{
cin>>a;
book.clear();
sum=0;
// cout<<ch<<endl;
biaoji(0,0,a.size()-1);
int ans=0;
map<long long,int>::iterator it;
for(it=book.begin();it!=book.end();it++) ans=max(ans,it->second) ;
// cout<<sum<<endl;
cout<<sum-ans<<endl;
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/zsyacm666666/p/4668002.html