-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathabc168-b.rs
47 lines (38 loc) · 1.02 KB
/
abc168-b.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
// https://atcoder.jp/contests/abc168/tasks/abc168_b
//
// 以下のクレートを使用。
// - `ascii`
// - `proconio`
use ascii::{AsciiStr, AsciiString};
use proconio::input;
fn main() {
// `str`/`String`や`[u8]`/`Vec<u8>`のかわりに`ascii::AsciiStr`/`ascii/AsciiString`を使うことができる。
//
// https://docs.rs/ascii/1.0.0/ascii/struct.AsciiStr.html
// https://docs.rs/ascii/1.0.0/ascii/struct.AsciiString.html
// `proconio::input!`。
//
// https://docs.rs/proconio/0.3.6/proconio/macro.input.html
input! {
k: usize,
mut s: AsciiString,
}
if s.len() > k {
s.truncate(k);
s += AsciiStr::from_ascii(b"...").unwrap();
}
println!("{}", s);
}
// 参考: Sを`Vec<u8>`で取った場合
const _: fn() = || {
use proconio::marker::Bytes;
input! {
k: usize,
mut s: Bytes,
}
if s.len() > k {
s.truncate(k);
s.extend_from_slice(b"...");
}
println!("{}", String::from_utf8(s).unwrap());
};