Skip to content

Commit f4c96aa

Browse files
committed
Add a test for APG4b-EX25
1 parent 85378b7 commit f4c96aa

File tree

14 files changed

+127
-0
lines changed

14 files changed

+127
-0
lines changed

examples/apg4b-ex25.rs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
use fixedbitset::FixedBitSet;
2+
use itertools::Itertools as _;
3+
4+
fn main() {
5+
// use std::io::{self, Read as _};
6+
//
7+
// let mut input = "".to_owned();
8+
// io::stdin().read_to_string(&mut input).unwrap();
9+
// let mut input = input.split_whitespace();
10+
// macro_rules! read {
11+
// ([$t:tt; $n:expr]) => {
12+
// (0..$n).map(|_| read!($t)).collect::<Vec<_>>()
13+
// };
14+
// (($($t:tt),+)) => {
15+
// ($(read!($t)),*)
16+
// };
17+
// (_1based) => {
18+
// read!(usize) - 1
19+
// };
20+
// (_bytes) => {
21+
// read!(String).into_bytes()
22+
// };
23+
// ($ty:ty) => {
24+
// input.next().unwrap().parse::<$ty>().unwrap()
25+
// };
26+
// }
27+
//
28+
// let n = read!(usize);
29+
// let a = read!([usize; n]);
30+
// let m = read!(usize);
31+
// let b = read!([usize; m]);
32+
// let arg0 = read!(String);
33+
// let args = read!([usize; if arg0 == "subtract" { 1 } else { 0 }]);
34+
35+
use proconio::input;
36+
37+
input! {
38+
n: usize,
39+
a: [usize; n],
40+
m: usize,
41+
b: [usize; m],
42+
arg0: String,
43+
args: [usize; if arg0 == "subtract" { 1 } else { 0 }],
44+
}
45+
46+
let (a, b) = (a.into_iter().collect(), b.into_iter().collect());
47+
48+
print_set(&match (&*arg0, &*args) {
49+
("intersection", []) => intersection(&a, &b),
50+
("union_set", []) => union_set(&a, &b),
51+
("symmetric_diff", []) => symmetric_diff(&a, &b),
52+
("subtract", &[x]) => subtract(a, x),
53+
("increment", []) => increment(&a),
54+
("decrement", []) => decrement(&a),
55+
_ => unreachable!(),
56+
});
57+
}
58+
59+
fn print_set(set: &FixedBitSet) {
60+
println!("{}", (0..50).filter(|&i| set[i]).format(" "));
61+
}
62+
63+
fn intersection(a: &FixedBitSet, b: &FixedBitSet) -> FixedBitSet {
64+
a & b
65+
}
66+
67+
fn union_set(a: &FixedBitSet, b: &FixedBitSet) -> FixedBitSet {
68+
a | b
69+
}
70+
71+
fn symmetric_diff(a: &FixedBitSet, b: &FixedBitSet) -> FixedBitSet {
72+
a ^ b
73+
}
74+
75+
fn subtract(mut a: FixedBitSet, x: usize) -> FixedBitSet {
76+
// > xは存在することが保証される。
77+
a.set(x, false);
78+
a
79+
}
80+
81+
fn increment(a: &FixedBitSet) -> FixedBitSet {
82+
a.ones().map(|x| (x + 1) % 50).collect()
83+
}
84+
85+
fn decrement(a: &FixedBitSet) -> FixedBitSet {
86+
a.ones().map(|x| (x + 49) % 50).collect()
87+
}

examples/tests.ron

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
name: "APG4b: A - 1.00.はじめに",
88
matching: ExactWhole,
99
),
10+
"apg4b-ex25": (
11+
name: "APG4b: EX25 - 集合の操作 / 3.05",
12+
matching: ExactWords,
13+
),
1014
"practice-a": (
1115
name: "practice contest: A - Welcome to AtCoder",
1216
matching: ExactWords,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
0 1 2
3+
3
4+
1 2 3
5+
intersection
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
0 1 2
3+
3
4+
1 2 3
5+
union_set
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
0 1 2
3+
3
4+
1 2 3
5+
symmetric_diff
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
0 1 2
3+
3
4+
1 2 3
5+
subtract 2
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
0 1 49
3+
3
4+
1 2 3
5+
increment
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
0 1 49
3+
3
4+
1 2 3
5+
decrement
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1 2
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0 1 2 3

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy