Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Practicas #196

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
83 changes: 83 additions & 0 deletions SegundaPractica.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import java.util.*;

public class SegundaPractica {

public static void main(String[] args) {
// TODO Auto-generated method stub

Scanner lee = new Scanner(System.in);

int num_problemas, minDisponibles;


System.out.println("Escribe cuantos problemas tiene y cuantos minutos dispone");
num_problemas = lee.nextInt();
minDisponibles = lee.nextInt();


int minXtarea[] = new int[num_problemas];

for(int i = 0; i<minXtarea.length; i++) {

System.out.print("Ingrese los minutos que le toma del problema "+(i+1)+": ");
minXtarea[i] = lee.nextInt();
}



//acomodarlos por insertionsort
for(int i = 0; i<minXtarea.length; i++) {
int temp = minXtarea[i];

int j = i-1;
for(;j>=0;j--) {
if(temp<minXtarea[j]) {
minXtarea[j+1]= minXtarea[j];
}else {
break;
}

}
minXtarea[j+1] = temp;

}



int contador = 0;
//problemas acomodados
for(int i = 0; i<minXtarea.length; i++) {

System.out.print(minXtarea[i]+" , ");

}


//prueba
int act = minDisponibles;
for(int i = 0; i<minXtarea.length; i++) {

if(minXtarea[i] <= act ) {
act-= minXtarea[i];
contador++;
}else {
break;
}

}


if(contador>0) {
System.out.println("\nTareas que puede realizar solo son: "+contador);
}else {
System.out.println("\n0 tareas a realizar");
}







}
}
26 changes: 26 additions & 0 deletions ago-dic-2024/Erika Delgado/Practica 1/PrimeraPractica.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.util.Scanner;

public class PrimeraPractica {

public static void main(String[] args) {


int n1,n2;

Scanner lee = new Scanner(System.in);

System.out.println("Ingrese los numeros dando un espacio ejemplo n1 ' ' n2'");
n1 = lee.nextInt();
n2 = lee.nextInt();

int resultado;

resultado = n1+n2;

System.out.println("El resultado es: "+resultado);



}

}
83 changes: 83 additions & 0 deletions ago-dic-2024/Erika Delgado/Practica 2/SegundaPractica.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import java.util.*;

public class SegundaPractica {

public static void main(String[] args) {
// TODO Auto-generated method stub

Scanner lee = new Scanner(System.in);

int num_problemas, minDisponibles;


System.out.println("Escribe cuantos problemas tiene y cuantos minutos dispone");
num_problemas = lee.nextInt();
minDisponibles = lee.nextInt();


int minXtarea[] = new int[num_problemas];

for(int i = 0; i<minXtarea.length; i++) {

System.out.print("Ingrese los minutos que le toma del problema "+(i+1)+": ");
minXtarea[i] = lee.nextInt();
}



//acomodarlos por insertionsort
for(int i = 0; i<minXtarea.length; i++) {
int temp = minXtarea[i];

int j = i-1;
for(;j>=0;j--) {
if(temp<minXtarea[j]) {
minXtarea[j+1]= minXtarea[j];
}else {
break;
}

}
minXtarea[j+1] = temp;

}



int contador = 0;
//problemas acomodados
for(int i = 0; i<minXtarea.length; i++) {

System.out.print(minXtarea[i]+" , ");

}


//prueba
int act = minDisponibles;
for(int i = 0; i<minXtarea.length; i++) {

if(minXtarea[i] <= act ) {
act-= minXtarea[i];
contador++;
}else {
break;
}

}


if(contador>0) {
System.out.println("\nTareas que puede realizar solo son: "+contador);
}else {
System.out.println("\n0 tareas a realizar");
}







}
}
41 changes: 41 additions & 0 deletions ago-dic-2024/Erika Delgado/Practica 3/TerceraPractica.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import java.util.*;
public class TerceraPractica {

public static void main(String[] args) {

//ordenando pokemones


Scanner lee = new Scanner(System.in);


int poderPokemon[] = {534,234,120,70,212} ;
//pokemones iniciales
System.out.println("Poder pokemon");
for(int ele:poderPokemon) {
System.out.print(ele+" ");
}

System.out.println();
for(int i=0; i<poderPokemon.length; i++) {
int minimo = i;
for(int p=i+1;p<poderPokemon.length;p++) {
if(poderPokemon[minimo] < poderPokemon[p]) {
minimo = p;
}
}

int aux = poderPokemon[i];
poderPokemon[i] = poderPokemon[minimo];
poderPokemon[minimo] = aux;
}

//pokemones acomodados
System.out.println("\nPoder pokemon acomodados");
for(int ele:poderPokemon) {
System.out.print(ele+" ");
}

}

}
77 changes: 77 additions & 0 deletions ago-dic-2024/Erika Delgado/Practica 4/Practica4.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import java.util.Scanner;

import javax.swing.JOptionPane;

public class Practica4 {

public String[]mergesort(String[]arr){
if(arr.length == 1) {
return arr;
}
int mitad = arr.length /2;
String[]izq = new String[mitad];
String der[]= new String[arr.length-mitad];

for(int i=0; i<mitad;i++) {
izq[i]= arr[i];
}

for(int i=0; i<der.length;i++) {
der[i]= arr[mitad+i];
}

String[]sorted_left = mergesort(izq);
String[]sorted_right = mergesort(der);

return merge(sorted_left,sorted_right);


}

public String[]merge(String []left,String right[]){
String[] arr_resultado = new String[left.length + right.length];
int i = 0, j = 0, k = 0;

while (i < left.length && j < right.length) {
if (left[i].compareTo(right[j]) <= 0) {
arr_resultado[k++] = left[i++];
} else {
arr_resultado[k++] = right[j++];
}
}

while (i < left.length) {
arr_resultado[k++] = left[i++];
}

while (j < right.length) {
arr_resultado[k++] = right[j++];
}

return arr_resultado;
}


public static void main(String[] args) {

Scanner lee = new Scanner(System.in);
Practica4 p = new Practica4();

int n = Integer.parseInt(JOptionPane.showInputDialog("Ingrese la cantidad de palabras"));
String[] palabras = new String[n];

System.out.println("Escriba la cadena de texto por espacios:");
for (int i = 0; i < palabras.length; i++) {
palabras[i] = lee.next();
}

String[] nvo = p.mergesort(palabras);

// Mostrar arreglo
System.out.println("Palabras ordenadas:");
for (String elemento : nvo) {
System.out.print(elemento + " ");
}
}

}
Loading