Skip to content

Commit 16afefe

Browse files
committed
fixed ComtestPrinter::printArray
With the old implementation, ContestPrinter throws unintended exception when the length of the array is zero. The bug is now removed!
1 parent c142142 commit 16afefe

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

ContestIO/ContestPrinter.java

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public void println(double d){
4545

4646
public void printArray(int[] array, String separator){
4747
int n = array.length;
48+
if(n==0){
49+
super.println();
50+
return;
51+
}
4852
for(int i=0; i<n-1; i++){
4953
super.print(array[i]);
5054
super.print(separator);
@@ -56,6 +60,10 @@ public void printArray(int[] array){
5660
}
5761
public void printArray(int[] array, String separator, java.util.function.IntUnaryOperator map){
5862
int n = array.length;
63+
if(n==0){
64+
super.println();
65+
return;
66+
}
5967
for(int i=0; i<n-1; i++){
6068
super.print(map.applyAsInt(array[i]));
6169
super.print(separator);
@@ -68,6 +76,10 @@ public void printArray(int[] array, java.util.function.IntUnaryOperator map){
6876

6977
public void printArray(long[] array, String separator){
7078
int n = array.length;
79+
if(n==0){
80+
super.println();
81+
return;
82+
}
7183
for(int i=0; i<n-1; i++){
7284
super.print(array[i]);
7385
super.print(separator);
@@ -79,6 +91,10 @@ public void printArray(long[] array){
7991
}
8092
public void printArray(long[] array, String separator, java.util.function.LongUnaryOperator map){
8193
int n = array.length;
94+
if(n==0){
95+
super.println();
96+
return;
97+
}
8298
for(int i=0; i<n-1; i++){
8399
super.print(map.applyAsLong(array[i]));
84100
super.print(separator);
@@ -88,5 +104,34 @@ public void printArray(long[] array, String separator, java.util.function.LongUn
88104
public void printArray(long[] array, java.util.function.LongUnaryOperator map){
89105
this.printArray(array, " ", map);
90106
}
91-
107+
public void printArray(Object[] array, String separator){
108+
int n = array.length;
109+
if(n==0){
110+
super.println();
111+
return;
112+
}
113+
for(int i=0; i<n-1; i++){
114+
super.print(array[i]);
115+
super.print(separator);
116+
}
117+
super.println(array[n-1]);
118+
}
119+
public void printArray(Object[] array){
120+
this.printArray(array, " ");
121+
}
122+
public void printArray(Object[] array, String separator, java.util.function.UnaryOperator map){
123+
int n = array.length;
124+
if(n==0){
125+
super.println();
126+
return;
127+
}
128+
for(int i=0; i<n-1; i++){
129+
super.print(map.apply(array[i]));
130+
super.print(separator);
131+
}
132+
super.println(map.apply(array[n-1]));
133+
}
134+
public void printArray(Object[] array, java.util.function.UnaryOperator map){
135+
this.printArray(array, " ", map);
136+
}
92137
}

0 commit comments

Comments
 (0)