Skip to content

Instantly share code, notes, and snippets.

@manucorporat
Last active December 11, 2015 17:48
Show Gist options
  • Save manucorporat/4637010 to your computer and use it in GitHub Desktop.
Save manucorporat/4637010 to your computer and use it in GitHub Desktop.
First test, Computer Sciences, Universidad de Valladolid, January 2013.
// PART 3
static void metodo3(NotaAlumnoAsignatura [] a)
{
int current = a[0].numAlumno;
double total = 0;
int nuNotas = 0;
try {
PrintWriter salida = new PrintWriter(new FileWriter("Notas.txt"));
for(int i = 0; i < a.lenght; ++i) {
if(current != a[i].numAlumno) {
salida.println(a[i-1].nombre+" "+(total/nuNotas));
total = 0;
nuNotas = 0;
}
total += a[i].nota;
++nuNotas;
}
salida.println(a[a.length-1].nombre+" "+(total/nuNotas));
salida.close();
} catch(IOException e) {
System.out.println("Error abriendo Notas.txt");
}
}
// PART 1
static void binary(int nu) {
if(nu != 0) {
binary(nu/2);
System.out.println((nu%2)+"");
}
}
// PART 2
static int[] metodo1(String str) {
int [] a = new int[10];
for(int i = 0; i < 10; ++i)
a[i] = -1;
for(int i = 0; i < str.length(); ++i)
a[(int)(str.charAt(i)-'0')] = i;
return a;
}
static String metodo2(int [] a) {
String str = "";
int current = 0;
int i = 0;
boolean found = true;
while(current < 10 && found == true) {
found = false;
while(i < a.lenght && found == false) {
if(a[i] == current) {
str.concat(i+"");
found = true;
}
++i;
}
++current;
}
// PART 4
class NotasCurso {
public char grupo;
public int curso;
public double [][] notas;
NotasCurso() {
this.grupo = '0';
this.curso = 0;
this.notas = new double[NAL][NASIGN];
for(int x = 0; x < NAL; ++x)
for(int y = 0; y < NASIGN; ++y)
this.notas[x][y] = 0;
}
NotasCurso(char grupo, int curso, NotasAlumnoAsignatura [] a) {
this();
this.grupo = grupo;
this.curso = curso;
for(int i = 0; i < a.length; ++i)
this.notas[a[i].numAlumno][a[i].numAsignatura] = a[i].nota;
}
static double mediaAlumno(NotasCurso c, int alumno) {
double total = 0;
for(int i = 0; i < NASIGN; ++i)
total += c.notas[alumno][i];
return (total / NASIGN);
}
double mediaAsignatura(int asignatura) {
double total = 0;
for(int i = 0; i < NAL; ++i)
total += this.notas[i][asignatura];
return (total / NAL);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment