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
141
142
143
144
145
146
147
148
149
150
151
152
153
//! A macro to convert function input and output to stdio
//!
//! This macro changes the arguments and return value of a function to take them from standard input and output.
//!
//! ```should_panic
//! # use argio::argio;
//! #[argio]
//! fn main(n: i32) -> i32 {
//! n * 2
//! }
//! ```
//!
//! Instead of taking an integer as an argument, this function reads an integer from the standard input and outputs the result to the standard output.
//!
//! Because this macro uses [proconio](https://crates.io/crates/proconio) as a backend for input, you can put the same arguments as those that can be passed to the `input!` macro of `proconio` in the function (even if they are not the correct syntax for Rust).
//!
//! ```should_panic
//! # use argio::argio;
//! #[argio]
//! fn main(n: usize, x: [i64; n]) -> i64 {
//! x.into_iter().sum()
//! }
//! ```
//!
//! This function takes such an input
//!
//! ```text
//! N
//! x_1 x_2 ... x_N
//! ```
//!
//! from the standard input and outputs the sum to the standard output.
//!
//! You can change the macro for the input by setting the `input` parameter. A macro takes the arguments of the function as they are.
//!
//! ```compile_fail
//! # use argio::argio;
//! macro_rules! my_input {
//! ...
//! }
//!
//! #[argio(input = my_input)]
//! fn main(n: usize, x: [i64; n]) -> i64 {
//! x.into_iter().sum()
//! }
//! ```
//!
//! Because the `Display` trait is used to display the return value, functions such as `Vec` which does not implement the `Display` trait cannot be compiled as it is.
//!
//! You can customize the behavior of the output by using a wrapper struct that implements the `Display` trait.
//!
//! ```should_panic
//! # use argio::argio;
//! # use std::{fmt, fmt::Display};
//! struct Wrap<T>(T);
//!
//! impl<T: Display> Display for Wrap<Vec<T>> {
//! fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
//! for (ix, r) in self.0.iter().enumerate() {
//! if ix > 0 {
//! write!(f, " ")?;
//! }
//! r.fmt(f)?;
//! }
//! Ok(())
//! }
//! }
//!
//! #[argio]
//! fn main(n: usize) -> Wrap<Vec<usize>> {
//! Wrap((0..n).map(|i| i * 2).collect())
//! }
//! ```
//!
//! ```text
//! $ echo 10 | cargo run
//! 0 2 4 6 8 10 12 14 16 18
//! ```
//!
//! Of course, you can also output manually. If the return value of the function is `()`, it does not output anything to the standard output, so you can output it manually and return `()`.
//!
//! ```should_panic
//! # use argio::argio;
//! #[argio]
//! fn main(n: usize) {
//! let ans = (0..n).map(|i| i * 2).collect::<Vec<_>>();
//! for (i, x) in ans.into_iter().enumerate() {
//! if i > 0 {
//! print!(" ");
//! }
//! print!("{}", x);
//! }
//! println!();
//! }
//! ```
//!
//! You can also specify a wrapper for the output from a macro parameter. This has the advantage of removing information about the wrapper from the code, allowing you to move the output customization to the template part of the code.
//!
//! ```should_panic
//! # use argio::argio;
//! # use std::fmt::{self, Display};
//! # struct Wrap<T>(T);
//! # impl<T: Display> Display for Wrap<Vec<T>> {
//! # fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
//! # for (ix, r) in self.0.iter().enumerate() {
//! # if ix > 0 {
//! # write!(f, " ")?;
//! # }
//! # r.fmt(f)?;
//! # }
//! # Ok(())
//! # }
//! # }
//! #[argio(output = Wrap)]
//! fn main(n: usize) -> Vec<usize> {
//! (0..n).map(|i| i * 2).collect()
//! }
//! ```
//!
//! If `multicase` is specified as an attribute, it can be used to automatically execute multiple inputs for multiple cases that start with the number of cases.
//!
//! The value of the attribute `multicase` is a string to be displayed at the top of each case. The variable `i` contains the case number of 0 origin, so you can customize the display by using it.
//!
//! ```should_panic
//! # use argio::argio;
//! # use std::fmt::{self, Display};
//! # struct Wrap<T>(T);
//! # impl<T: Display> Display for Wrap<Vec<T>> {
//! # fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
//! # for (ix, r) in self.0.iter().enumerate() {
//! # if ix > 0 {
//! # write!(f, " ")?;
//! # }
//! # r.fmt(f)?;
//! # }
//! # Ok(())
//! # }
//! # }
//! #[argio(multicase = "Case #{i+1}: ", output = Wrap)]
//! fn main(n: usize) -> Vec<usize> {
//! (0..n).map(|i| i * 2).collect()
//! }
//! ```
//!
//! ```text
//! $ echo "3 2 3 5" | cargo run
//! Case #1: 0 2
//! Case #2: 0 2 4
//! Case #3: 0 2 4 6 8
//! ```
pub use argio;
pub use proconio;