Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
muuchas funciones utiles
#include <stdio.h> #define BASE 10000 void poblar(double *, int *, int); void mostrar(double *, int); void ordenar(double *, int *, int); int buscarJugador(int *, int, int); int main() { int cantJugadores; int edadBuscada; scanf("%i", &cantJugadores); double vPuntaje[cantJugadores]; int vEdades[cantJugadores]; poblar(vPuntaje, vEdades, cantJugadores); printf("Lista Inicial de Jugadores\n"); mostrar(vPuntaje, cantJugadores); ordenar(vPuntaje, vEdades, cantJugadores); printf("\nLista Ordenada de Jugadores\n"); mostrar(vPuntaje, cantJugadores); scanf("%i", &edadBuscada); int posicion = buscarJugador(vEdades, cantJugadores, edadBuscada); printf("\n"); if(posicion == -1) { printf("No se encontro ningun jugador que cumpliera la condicion\n"); } else { printf("El jugador de edad %i que obtuvo mayor puntaje obtuvo %.2lf puntos\n", edadBuscada, vPuntaje[posicion]); } int mitad = cantJugadores / 2; printf("El jugador que se encuentra en la mitad de la lista obtuvo %.2lf puntos", vPuntaje[mitad]); } void poblar(double *vPuntaje, int *vEdades, int n) { int trofeos; double horas; int edad; for(int i = 0 ; i < n ; i++) { scanf("%i %lf %i", &trofeos, &horas, &edad); vPuntaje[i] = (trofeos / (60 * horas)) * BASE; vEdades[i] = edad; } } void mostrar(double *vPuntaje, int n) { for(int i = 0 ; i < n ; i++) { printf("Jugador %i: tiene %.2lf puntos\n", i+1, vPuntaje[i]); } } void ordenar(double *vPuntaje, int *vEdades, int n) { double aux; int aux2; for(int i = 0 ; i < n - 1 ; i++) { for(int j = i + 1 ; j < n ; j++) { if(vPuntaje[i] < vPuntaje[j]) { aux = vPuntaje[i]; aux2 = vEdades[i]; vPuntaje[i] = vPuntaje[j]; vEdades[i] = vEdades[j]; vPuntaje[j] = aux; vEdades[j] = aux2; } else { if((vPuntaje[i] == vPuntaje[j]) && (vEdades[i] > vEdades[j])) { aux2 = vEdades[i]; vEdades[i] = vEdades[j]; vPuntaje[j] = aux; vEdades[j] = aux2; } } } } } int buscarJugador(int *vEdades, int n, int edadBuscada) { int posicion = -1; for(int i = 0 ; i < n ; i++) { if(vEdades[i] == edadBuscada) { posicion = i; break; } } return posicion; }
run
|
edit
|
history
|
help
0
a1
Memory leak
C_141127_Matriz01
linkedlist
stringify
BMI Calc CT
Rotación matriz anti horaria
pattern 12
Project 4 v0.1
18BCE2182 ASSESS_2 Q1