-
Notifications
You must be signed in to change notification settings - Fork 0
/
IFJ16.java
130 lines (115 loc) · 2.92 KB
/
IFJ16.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
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
import java.io.*;
class ifj16
{
private static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
private static int readErrCode = 7;
private static int runErrCode = 10;
public static void main(String[] args)
{
Main.run(); // ignore command-line arguments since IFJ16 does not support arrays in the basic specification
}
public static void print(String message)
{
System.out.print(message);
}
public static void print(int i)
{
System.out.print(i);
}
public static void print(double d)
{
System.out.print(d);
}
public static int readInt()
{
int i = 0;
try {
i = Integer.parseInt(in.readLine());
}
catch (NumberFormatException e) {
System.err.println("Input error - Invalid value for an int.");
System.exit(readErrCode);
return 0;
}
catch (NullPointerException e) {
System.err.println("Input error - null result from readLine; the result will be 0.");
System.exit(readErrCode);
return 0;
}
catch (IOException e) {
System.err.println("Input error - IOException occured; the result will be 0.");
System.exit(readErrCode);
return 0;
}
return i;
}
public static double readDouble()
{
double d = Double.NaN;
try {
d = Double.parseDouble(in.readLine());
}
catch (NumberFormatException e) {
System.err.println("Input error - Invalid value for a double.");
System.exit(readErrCode);
return 0.0;
}
catch (NullPointerException e) {
System.err.println("Input error - null result from readLine.");
System.exit(readErrCode);
return 0.0;
}
catch (IOException e) {
System.err.println("Input error - IOException occured.");
System.exit(readErrCode);
return 0.0;
}
return d;
}
public static String readString()
{
String s;
try {
s = in.readLine();
}
catch (IOException e) {
System.err.println("Input error - IOException occured; the result will be the empty string.");
return "";
}
if (s == null) {
System.err.println("Input error - null result from readLine; the result will be empty string.");
return "";
}
return s;
}
public static int length(String s)
{
return s.length();
}
public static String substr(String s, int i, int n)
{
try {
return s.substring(i, i+n);
}
catch (IndexOutOfBoundsException e) {
System.err.println("Substr error - IndexOutOfBoundsException occured.");
System.exit(runErrCode);
return "";
}
}
public static int compare(String s1, String s2)
{
return s1.compareTo(s2);
}
public static int find(String s, String search)
{
return s.indexOf(search);
}
public static String sort(String s)
{
char[] c = s.toCharArray();
java.util.Arrays.sort(c);
return new String(c);
}
}
/* Zde bude nasledovat program jazyka IFJ16 */