-
Notifications
You must be signed in to change notification settings - Fork 0
/
488.java
91 lines (77 loc) · 2.08 KB
/
488.java
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
package apr;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
try {
new uva.ProblemSolution().Solution();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
class uva {
public static class ProblemSolution {
private static int testCase, amplitude, frequency;
public void Solution() {
testCase = scanner.nextInt();
for (int test = 1; test <= testCase; test++) {
amplitude = scanner.nextInt();
frequency = scanner.nextInt();
String str = makeTriangleWave(amplitude);
for (int i = 1; i <= frequency; i++) {
System.out.print(str);
if (i < frequency)
System.out.println('\n');
}
if (test < testCase)
System.out.println("\n");
else
System.out.println();
}
scanner.close();
}
}
private static String makeTriangleWave(int amplitude) {
String str = "";
int back, backCounter = 0;
for (int i = 1; i <= amplitude * 2 - 1; i++) {
if (i <= amplitude) {
back = i;
} else {
backCounter += 2;
back = i - backCounter;
}
for (int j = 1; j <= back; j++) {
if (i <= amplitude) {
str += i;
} else {
str += i - backCounter;
}
}
if (i <= 2 * amplitude - 2) {
str += '\n';
}
}
return str;
}
/*
* Printer
*/
// private static PrintWriter out = new PrintWriter(System.out, true);
// private static DataOutputStream out = new DataOutputStream(System.out);
/*
* scanner
*/
// private static DataInputStream scanner = new DataInputStream(System.in);
// private static BufferedReader scanner = new BufferedReader( new
// InputStreamReader(System.in));
private static Scanner scanner = new Scanner(System.in);
// private static Scanner scanner = fileFactory.scanner();
// private static BufferedReader scanner = fileFactory.bufferedRader();
}