Documentos de Académico
Documentos de Profesional
Documentos de Cultura
{
int r=-1;
int l = input1.length;
if(l%2==0 || l<=0){
return r;
}
for(int i =0; i<l; i++){
int[] q = remove_int(input1, i);
int l1= q.length;
int l2 = l1/2;
int combin=factorial(l1)/(factorial(l2)* factorial(l1-l2));
System.out.println(" "+ combin);
s= new String[combin];
saveCombination(q, l1,l2);
int m= aretwosame(s);
if(m!=1){
r=-1;
return r;
}
else{
r=m;
}
}
return r;
//Write code here
}
public static int getvalue(String x){
int i=0;
x=x+" ";
int l= x.length();String g="";
for(int j=0; j<l; j++){
char c=x.charAt(i);
if(c==' '){
i=i+Integer.parseInt(g);
g="";
}
else{
g=g+c;
}
}
return i;
}
public static int aretwosame(String[] d){
int l= d.length;
int[] e= new int[l];
for(int i=0; i<l; i++){
e[i] = getvalue(d[i]);
}
int f= twointsame(e);
return f;
}
public static int twointsame(int[] d){
int l = d.length;
int c=-1;
for(int i=0; i<l; i++){
for(int j=0; j<l && i!=j; j++){
if(d[i]==d[j]){
c=1;
}
}
}
return c;
}
public static int[] remove_int(int[] a, int p){
int l = a.length;
int k=l-1;
int[] r = new int[k];int j=0;
for(int i=0; i<l;i++){
if(i!=p){
r[j]=a[i];
j++;
}
}
return r;
}
public static int factorial(int n){
int i=1;
while( n>0){
i=i*n;
n--;
}
return i;
}
static String[] s; static int z=0;
static void combinationUtil(int arr[], int data[], int start,
int end, int index, int r)
{
if (index == r)
{
for (int j=0; j<r; j++){
Syste
s[z] = s[z]+" "+data[j];
}
z++;
return;
}