-
Notifications
You must be signed in to change notification settings - Fork 0
/
off_10327.rs
50 lines (45 loc) · 1.34 KB
/
off_10327.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
pub fn main() {
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap_or_default();
let inputs: Vec<&str> = input.split(' ').collect();
let n: i32 = inputs.first()
.unwrap_or(&"")
.trim().parse()
.unwrap_or_default();
let t = inputs.last().unwrap().trim();
let key = get_unique_chars(t);
let mut offs: Vec<String> = vec![];
for _i in 0..n {
let mut temp = String::new();
std::io::stdin().read_line(&mut temp).unwrap_or_default();
offs.push(temp.trim().parse().unwrap_or_default());
}
for off in offs {
let off_uniques = get_unique_chars(off.as_str());
if off_uniques.len() != key.len() {
println!("No")
} else {
let mut is_unique = true;
for off_unique in off_uniques {
is_unique = is_unique && key.contains(&off_unique);
if !is_unique {
break;
}
}
if is_unique {
println!("Yes");
} else {
println!("No");
}
}
}
}
fn get_unique_chars(input: &str) -> Vec<char> {
let mut uniques: Vec<char> = vec![];
for char in input.chars() {
if !uniques.contains(&char) {
uniques.push(char);
}
}
uniques
}