Homework B (benchmarks)

This commit is contained in:
Carlos Galindo 2020-01-15 22:38:07 +01:00
parent 72cc3206c4
commit 76fbabdf53
Signed by: kauron
GPG key ID: 83E68706DEE119A3
141 changed files with 7540 additions and 2032 deletions

View file

@ -0,0 +1,60 @@
// Overall test of arrays, loops, etc. that does a simple quicksort.
class Record {
int a ;
}
class Main {
Record [] a;
int i;
void swap(Record r1, Record r2) {
int temp;
temp = 0+1;
temp = r1.a;
r1.a = r2.a;
r2.a = temp;
}
void sort(int left, int right) {
int i,j;
int m;
m = (a[left].a + a[right].a) / (1 + 1);
i = left;
j = right;
while (i <= j) {
while (a[i].a < m) { i = i+1; }
while (a[j].a > m) { j = j-1; }
if (i <= j) {
swap(a[i], a[j]);
i = i+1;
j = j-1;
}
}
if (left < j) { sort(left,j); }
if (i < right) { sort(i,right); }
}
void main() {
int SIZE;
int j;
SIZE = 10;
a = new Record[SIZE * 1];
j = 0;
while (j < SIZE) {
a[j] = new Record();
a[j].a = read();
j = j + 1;
}
sort(0, SIZE-1);
j = 0;
while (j < SIZE) {
i = a[j].a;
write(i);
writeln();
j = j + 1;
}
}
}

View file

@ -0,0 +1,10 @@
1
5
6
7
8
5
2
4
6
3

View file

@ -0,0 +1,40 @@
class Main {
int SIZE;
void main() {
int[] a;
int i;
int pi;
int e;
int thou;
pi = 3141;
e = 2718;
a = readStuff();
i = 0;
while(i < SIZE) {
write(pi * e * a[i] / (1000 * 1000));
writeln();
write(a[i] * pi * e / (1000 * 1000));
writeln();
i = i + 1;
}
}
int[] readStuff() {
int[] a;
int i;
SIZE = 5;
a = new int[SIZE];
i = 0;
while (i < SIZE) {
a[i] = read();
i = i + 1;
}
return a;
}
}

View file

@ -0,0 +1,5 @@
42
1337
9000
12345678
777

View file

@ -0,0 +1,13 @@
class Main {
void main() {
int i;
int j;
i = read();
j = 2 * i;
i = (i + 31) / 2;
j = (i * j) / 3;
write(i);
}
}

View file

@ -0,0 +1 @@
43