-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray.rs
75 lines (68 loc) · 1.72 KB
/
array.rs
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
struct Scan {
buffer: std::collections::VecDeque<String>,
}
impl Scan {
fn new() -> Scan {
Scan {
buffer: std::collections::VecDeque::new(),
}
}
fn next_line(&self) -> String {
let mut line = String::new();
std::io::stdin().read_line(&mut line).expect("Fail to read");
line
}
fn next<T: std::str::FromStr>(&mut self) -> T {
loop {
if let Some(token) = self.buffer.pop_front() {
break token.parse::<T>().ok().unwrap();
}
let line = self.next_line();
self.buffer = line.split_whitespace().map(String::from).collect();
}
}
fn next_n<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
(0..n).map(|_| self.next::<T>()).collect()
}
}
fn print_arr(x: &[isize]) {
print!("{} ", x.len());
for item in x {
print!("{} ", item);
}
println!();
}
fn _main() {
let mut scan = Scan::new();
let n: usize = scan.next();
let arr: Vec<isize> = scan.next_n(n);
let mut first: Vec<isize> = vec![];
let mut second: Vec<isize> = vec![];
let mut third: Vec<isize> = vec![];
for item in arr {
if item > 0 {
second.push(item);
} else if item < 0 {
first.push(item);
} else {
third.push(item);
}
}
if first.len() % 2 == 0 {
third.push(first.pop().unwrap());
}
while first.len() > 1 {
second.push(first.pop().unwrap());
}
print_arr(&first);
print_arr(&second);
print_arr(&third);
}
fn main() {
std::thread::Builder::new()
.stack_size(1 << 23)
.spawn(_main)
.unwrap()
.join()
.unwrap();
}