-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.rs
41 lines (37 loc) · 1.32 KB
/
main.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
fn main() {
Solution::to_goat_latin("I speak Goat Latin".to_owned());
}
struct Solution {}
impl Solution {
pub fn to_goat_latin(sentence: String) -> String {
let mut res = vec![];
for (idx, i) in sentence.split(' ').enumerate() {
res.push(if i.to_lowercase().starts_with(['a', 'e', 'i', 'o', 'u']) {
format!("{}maa{}",i,"a".repeat(idx))
} else {
format!("{}{}maa{}",&i[1..],&i[..1],"a".repeat(idx))
})
}
// println!("res = {:#?}", res);
res.join(" ")
}
}
#[cfg(test)]
mod test {
use crate::*;
#[test]
fn basic() {
assert_eq!(
Solution::to_goat_latin("I speak Goat Latin".to_owned()),
"Imaa peaksmaaa oatGmaaaa atinLmaaaaa"
);
assert_eq!(
Solution::to_goat_latin("The quick brown fox jumped over the lazy dog".to_owned()),
"heTmaa uickqmaaa rownbmaaaa oxfmaaaaa umpedjmaaaaaa overmaaaaaaa hetmaaaaaaaa azylmaaaaaaaaa ogdmaaaaaaaaaa"
);
assert_eq!(
Solution::to_goat_latin("Ii wefj weofi woe eofiwejf owefi jowe r speak Goat Latin".to_owned()),
"Iimaa efjwmaaa eofiwmaaaa oewmaaaaa eofiwejfmaaaaaa owefimaaaaaaa owejmaaaaaaaa rmaaaaaaaaa peaksmaaaaaaaaaa oatGmaaaaaaaaaaa atinLmaaaaaaaaaaaa"
);
}
}