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
use iof::{read, Mat};
/// Some examples of reading from standard input.
///
/// We use a `v` to indicate the cursor position.
fn main() {
// Read a single integer from input.
//
// v
// 42 abc def
let n: u32 = read!();
assert_eq!(n, 42);
// Read a single string from input.
//
// v
// 42 abc def
let n: String = read!();
assert_eq!(n, "abc");
// Read a vector of characters from input.
// Spaces are ignored, and those characters need not be separated by spaces.
//
// v
// 42 abc def
let v: Vec<char> = read!();
assert_eq!(v, ['d', 'e', 'f']);
// Read a tuple from input. Equivalent to:
//
// ```
// let l: u32 = read!();
// let m: f64 = read!();
// let n: String = read!();
// ```
//
// v
// 0 0.3 lmn
let (l, m, n): (u32, f64, String) = read!();
assert_eq!(l, 0);
assert_eq!(m, 0.3);
assert_eq!(n, "lmn");
// Read a vector of integers from input.
// They are separated by spaces.
//
// v
// 1 2 3
let v: Vec<u32> = read!(3);
assert_eq!(v, [1, 2, 3]);
// Read a matrix of integers from input.
// They are separated by spaces, and newlines are unnecessary but useful for readability.
//
// v
// 1 2 3
// 4 5 6
let m: Mat<u32> = read!(2, 3);
assert_eq!(m, [[1, 2, 3], [4, 5, 6]]);
// Read a matrix of characters from input.
// Spaces are ignored and unnecessary, too.
//
// v
// .@/#$
// !@#!@
// *&@:,
let m: Mat<char> = read!(3, 5);
assert_eq!(
m,
[
['.', '@', '/', '#', '$'],
['!', '@', '#', '!', '@'],
['*', '&', '@', ':', ',']
]
);
}