Ver Mensaje Individual
  #3 (permalink)  
Antiguo 08/01/2008, 12:25
msilva
 
Fecha de Ingreso: enero-2008
Mensajes: 4
Antigüedad: 16 años, 5 meses
Puntos: 0
Re: Combinacion con recursividad

Bueno, gracias por responder..
Yo lo hice en Java, pero tengo problemas al cambiarme a c++ porque no lo se utilizar muy bien que se diga, tengo problemas con las cadenas de caracteres, si me puedes ayudar a pasarlo de Java a C++, estaría muy agradecida..

el programa hecho en Java es el siguiente:

public class Primero //clase principal
{
public static void main(String[] args)
{
Com("1",1);
}
public static int Imprimir(char[]v)// mostrar resultados
{
int tot=1;
int aux1=1;
for(int k=0; k<5; k++)
{
if((k%2)==0)
aux1=aux1+1;
else
{
if(v[k]=='+')
tot=tot+(aux1);
else
{
if(v[k]=='-')
tot=tot-(aux1);
else
{
if(v[k]=='*')
tot=tot*(aux1);
else
{
if(v[k]=='/')
tot=tot/(aux1);
}
}
}
}
}
int aux=4, count=0;
for(int j=5; j<17; j++)
{
if((j%2)==0)
aux=j;
else
{
if(v[j]=='+')
{
tot=tot+(aux-count);
count++;
}
else
{
if(v[j]=='-')
{
tot=tot-(aux-count);
count++;
}
else
{
if(v[j]=='*')
{
tot=tot*(aux-count);
count++;
}
else
{
if(v[j]=='/')
{
tot=tot/(aux-count);
count++;
}
}
}
}
}
}
return tot;
}
public static String Com(String uni,int N)//método recursivo
{
if(N==9)
return uni;
else
{
String a=uni;
String b=uni;
String c=uni;
uni=uni+"+"+(N+1);
a= a + "-" + (N+1);
b= b + "*" + (N+1);
c= c + "/" + (N+1);
if (a.length()==17)
{
int tot=0, t;
char v[]=new char[17];
for(int j=0; j<17; j++)
v[j]=a.charAt(j);
t=Imprimir(v);
if(t==100)
System.out.println(a);
}
if (b.length()==17)
{
int tot=0, i=0, t;
char v[]=new char[17];
for(int j=0; j<17; j++)
v[j]=b.charAt(j);
t=Imprimir(v);
if(t==100)
System.out.println(b);
}
if (c.length()==17)
{
int tot=0, i=0, t;
char v[]=new char[17];
for(int j=0; j<17; j++)
v[j]=c.charAt(j);
t=Imprimir(v);
if(t==100)
System.out.println(c);
}
if (uni.length()==17)
{
int tot=0, i=0, t;
char v[]=new char[17];
for(int j=0; j<17; j++)
v[j]=uni.charAt(j);
t=Imprimir(v);
if(t==100)
System.out.println(uni);
}
Com(uni,N+1);
Com(a,N+1);
Com(b,N+1);
Com(c,N+1);
return uni;
}
}
}