Commit 8cacd221 authored by uwdkn's avatar uwdkn

Merge branch 'exec-testcases' into 'master'

Exec Test Cases (Group 2)

See merge request !47
parents 7159e82f ffe05302
20
625
67
120
316
-191
-377
-103
353
384
240
-759
-566
-111
-623
874
-712
370
-372
-240
-288
1
-2147483648
2147483647
class Summator {
public int sum(int[] array, int len) {
int sum = 0;
int i = 0;
while(i < len) {
sum = sum + array[i];
i = i + 1;
}
return sum;
}
public int readInt() throws Exception {
int nextChar;
int sign = 1;
int number = 0;
int asciiZero = 48;
int asciiMinus = 45;
nextChar = System.in.read();
/* Check for sign */
if (nextChar == asciiMinus) {
sign = sign * (-1);
/* Advance */
nextChar = System.in.read();
}
/* CR/LF Characters */
while (nextChar != 10 && nextChar != 13) {
if (nextChar >= asciiZero && nextChar <= (asciiZero + 9)) {
/* Found a digit */
number = number * 10 + nextChar - asciiZero;
}
nextChar = System.in.read();
}
return sign * number;
}
public static void main(String[] args) throws Exception {
Summator acc = new Summator();
int arrayLen = acc.readInt();
int[] array = new int[arrayLen];
int i = 0;
while(i < arrayLen) {
array[i] = acc.readInt();
i = i + 1;
}
int arraySum = acc.sum(array, arrayLen);
System.out.println(arraySum);
}
}
50
47
7040
3741
4502
1682
8636
4694
6347
685
5099
7104
7485
2296
9589
6862
5569
2599
578
1353
1326
2916
3558
19
3762
288
1168
6562
296
8648
5199
6495
5299
784
8934
3561
6345
4321
4841
6709
2268
7336
9524
6170
3555
5789
5238
2928
3959
5864
1553
10
9
8
7
6
5
4
3
2
1
0
class BubbleSort {
public int[] sortArray;
public int length;
public void setArray(int[] sortArray, int length) {
this.sortArray = sortArray;
this.length = length;
}
public int readInt() throws Exception {
int nextChar;
int sign = 1;
int number = 0;
int asciiZero = 48;
int asciiMinus = 45;
nextChar = System.in.read();
/* Check for sign */
if (nextChar == asciiMinus) {
sign = sign * (-1);
/* Advance */
nextChar = System.in.read();
}
/* CR/LF Characters */
while (nextChar != 10 && nextChar != 13) {
if (nextChar >= asciiZero && nextChar <= (asciiZero + 9)) {
/* Found a digit */
number = number * 10 + nextChar - asciiZero;
}
nextChar = System.in.read();
}
return sign * number;
}
public void sort() {
boolean swapped = true;
while (swapped) {
swapped = false;
int i = 0;
while (i <= this.length - 2) {
if (this.sortArray[i] > this.sortArray[i + 1]) {
this.swap(i, i + 1);
swapped = true;
}
i = i + 1;
}
}
}
public void swap(int i, int j) {
int temp = this.sortArray[i];
this.sortArray[i] = this.sortArray[j];
this.sortArray[j] = temp;
}
public static void main(String[] args) throws Exception {
BubbleSort sort = new BubbleSort();
int arrayLen = sort.readInt();
int[] array = new int[arrayLen];
int i = 0;
while(i < arrayLen) {
array[i] = sort.readInt();
i = i + 1;
}
sort.setArray(array, arrayLen);
sort.sort();
/* Print array */
i = 0;
while (i < sort.length) {
System.out.println(sort.sortArray[i]);
i = i + 1;
}
}
}
class Printer {
public int lower;
public int upper;
public Printer init(int lower, int upper) {
this.lower = lower;
this.upper = upper;
return this;
}
public void print() {
int lower = 33; /* ! */
int upper = 126; /* ~ */
int i = lower;
while (i <= upper) {
System.out.write(i);
i = i + 1;
}
/* Write newline */
System.out.write(10);
System.out.flush();
}
public static void main(String[] args) {
int lower = 33; /* ! */
int upper = 126; /* ~ */
Printer printer = new Printer().init(lower, upper);
printer.print();
}
}
class Struct {
public int a;
public int b;
public boolean c;
public void printFields(Struct other) {
System.out.println(this.a + other.a);
System.out.println(this.b - other.b);
int result = 0;
if (this.c == other.c) result = 1;
System.out.println(result);
}
public void test() {
Struct other = new Struct();
other.a = 10;
other.b = -10;
other.c = false;
this.printFields(this);
this.printFields(other);
other.printFields(this);
}
public static void main(String[] args) {
Struct test = new Struct();
test.a = 23;
test.b = 42;
test.c = true;
test.test();
}
}
class UnreachableSideEffect {
public int a;
public UnreachableSideEffect init(int a) {
this.a = a;
return this;
}
public void test() {
this.a = 42;
return;
this.a = 23;
}
public static void main(String[] args) {
UnreachableSideEffect use = new UnreachableSideEffect().init(10);
System.out.println(use.a);
use.test();
System.out.println(use.a);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment