forked from NASU41/AtCoderLibraryForJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContestPrinter.java
More file actions
140 lines (134 loc) · 3.85 KB
/
ContestPrinter.java
File metadata and controls
140 lines (134 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
class ContestPrinter extends java.io.PrintWriter{
public ContestPrinter(java.io.PrintStream stream){
super(stream);
}
public ContestPrinter(java.io.File file) throws java.io.FileNotFoundException{
super(new java.io.PrintStream(file));
}
public ContestPrinter(){
super(System.out);
}
private static String dtos(double x, int n) {
StringBuilder sb = new StringBuilder();
if(x < 0){
sb.append('-');
x = -x;
}
x += Math.pow(10, -n)/2;
sb.append((long)x);
sb.append(".");
x -= (long)x;
for(int i = 0;i < n;i++){
x *= 10;
sb.append((int)x);
x -= (int)x;
}
return sb.toString();
}
@Override
public void print(float f){
super.print(dtos(f, 20));
}
@Override
public void println(float f){
super.println(dtos(f, 20));
}
@Override
public void print(double d){
super.print(dtos(d, 20));
}
@Override
public void println(double d){
super.println(dtos(d, 20));
}
public void printArray(int[] array, String separator){
int n = array.length;
if(n==0){
super.println();
return;
}
for(int i=0; i<n-1; i++){
super.print(array[i]);
super.print(separator);
}
super.println(array[n-1]);
}
public void printArray(int[] array){
this.printArray(array, " ");
}
public void printArray(int[] array, String separator, java.util.function.IntUnaryOperator map){
int n = array.length;
if(n==0){
super.println();
return;
}
for(int i=0; i<n-1; i++){
super.print(map.applyAsInt(array[i]));
super.print(separator);
}
super.println(map.applyAsInt(array[n-1]));
}
public void printArray(int[] array, java.util.function.IntUnaryOperator map){
this.printArray(array, " ", map);
}
public void printArray(long[] array, String separator){
int n = array.length;
if(n==0){
super.println();
return;
}
for(int i=0; i<n-1; i++){
super.print(array[i]);
super.print(separator);
}
super.println(array[n-1]);
}
public void printArray(long[] array){
this.printArray(array, " ");
}
public void printArray(long[] array, String separator, java.util.function.LongUnaryOperator map){
int n = array.length;
if(n==0){
super.println();
return;
}
for(int i=0; i<n-1; i++){
super.print(map.applyAsLong(array[i]));
super.print(separator);
}
super.println(map.applyAsLong(array[n-1]));
}
public void printArray(long[] array, java.util.function.LongUnaryOperator map){
this.printArray(array, " ", map);
}
public <T> void printArray(T[] array, String separator){
int n = array.length;
if(n==0){
super.println();
return;
}
for(int i=0; i<n-1; i++){
super.print(array[i]);
super.print(separator);
}
super.println(array[n-1]);
}
public <T> void printArray(T[] array){
this.printArray(array, " ");
}
public <T> void printArray(T[] array, String separator, java.util.function.UnaryOperator<T> map){
int n = array.length;
if(n==0){
super.println();
return;
}
for(int i=0; i<n-1; i++){
super.print(map.apply(array[i]));
super.print(separator);
}
super.println(map.apply(array[n-1]));
}
public <T> void printArray(T[] array, java.util.function.UnaryOperator<T> map){
this.printArray(array, " ", map);
}
}