private static int findSpouseIndex(String target,char source,char spouse){
return findSpouseIndex(target, source, spouse, 1);
}
private static int findSpouseIndex(String target,char source,char spouse,int bro){
int result = -1;
int count = 0;
for(int i = 0;i < target.length();i ++){
char next = target.charAt(i);
if(next == source){
count ++;
}else if(next == spouse){
count --;
if(count == 0){
if(bro == 1){
result = i;
break;
}
bro --;
}
}
}
return result;
}
private static int childNum(String str,char c,char c_spouse){
int result = 0;
int count = 0;
int index = str.indexOf(c);
for(int i = index;i < str.length();i++){
char next = str.charAt(i);
if(next == c){
count++;
}else{
if(next == c_spouse){
count--;
if(count == 0){
result++;
}
}
}
}
return result;
}
private static String[] toArray(String strArr){
int length = childNum(strArr,'{','}');
String[] str = new String[length];
int fromIndex = 0;
for(int i = 0;i < length;i ++){
int index_begin = strArr.indexOf('{',fromIndex);
int index_last = findSpouseIndex(strArr, '{','}',i+1);
str[i] = strArr.substring(index_begin,index_last+1);
fromIndex = index_last;
}
return str;
}