blob: 8951c30ae0741f2d86665da70abaea51e96f3671 (
plain)
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
|
#!/bin/sh
//usr/bin/env rustc --test $0 -o kachow && ./kachow --nocapture; rm -f kachow ; exit
// Ok this is kind of ugly, but hey it works
fn nice_string(s: &str) -> &str {
let mut longest = "";
for i in 0..s.len() {
for j in i..s.len() {
let sub = &s[i..=j];
if sub.chars().all(|c| {
!c.is_ascii_alphabetic()
|| sub.contains(c.to_ascii_lowercase()) && sub.contains(c.to_ascii_uppercase())
}) && sub.len() > longest.len()
{
longest = sub;
}
}
}
longest
}
#[test]
fn example() {
assert_eq!(nice_string("YaaAho"), "aaA");
assert_eq!(nice_string("cC"), "cC");
assert_eq!(nice_string("A"), "");
}
|