2 Solution for NEERC'2005 Problem Z: Zero-complexity Transposition
4 Note: this solution attempts to check correctness of the input
7 import java
.io
.BufferedReader
;
8 import java
.io
.FileReader
;
9 import java
.io
.FileWriter
;
10 import java
.io
.PrintWriter
;
11 import java
.util
.StringTokenizer
;
13 public class zero_re
{
14 static final int MAXN
= 10000;
15 static final long MAXABS
= 1000000000000000L;
17 public static void main(String
[] args
) throws Exception
{
19 BufferedReader in
= new BufferedReader(new FileReader("zero.in"));
20 int n
= Integer
.parseInt(in
.readLine());
21 if (n
< 1 || n
> MAXN
)
22 throw new IllegalArgumentException("n is out of range");
23 long[] a
= new long[n
];
24 StringTokenizer st
= new StringTokenizer(in
.readLine());
25 for (int i
= 0; i
< n
; i
++) {
26 a
[i
] = Long
.parseLong(st
.nextToken());
27 if (Math
.abs(a
[i
]) > MAXABS
)
28 throw new IllegalArgumentException("a[i] is out of range");
30 if (st
.hasMoreTokens())
31 throw new IllegalArgumentException("Extra data on line");
32 if (in
.readLine() != null)
33 throw new IllegalArgumentException("Extra data in file");
37 PrintWriter out
= new PrintWriter(new FileWriter("zero.out"));
39 for (int i
= n
; --i
>= 0;) {