AtCoder Beginner Contest 259 C

https://atcoder.jp/contests/abc260/tasks/abc259_c

groupbyを使えば簡単です。PartialEqとCopyが実装されていればOKのようです。

// XX to XXX
#![allow(non_snake_case)]

fn read<T: std::str::FromStr>() -> T {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).ok();
    line.trim().parse().ok().unwrap()
}

fn groupby<T: PartialEq+Copy>(v: &Vec<T>) -> Vec<Vec<T>> {
    let mut vs = Vec::<Vec<T>>::new();
    let mut prev = Vec::<T>::new();
    for &e in v.iter() {
        match prev.last() {
            Some(&f) => if e != f {
                            vs.push(prev.clone());
                            prev.clear()
                        },
            None     => ()
        }
        prev.push(e)
    }
    vs.push(prev);
    return vs
}

fn is_matched(S: &String, T: &String) -> bool {
    let vs1 = groupby(&S.chars().collect::<Vec::<char>>());
    let vs2 = groupby(&T.chars().collect::<Vec::<char>>());
    vs1.len() == vs2.len() &&
        vs1.iter().zip(vs2.iter()).all(|(e, f)| e[0] == f[0] &&
                                        ((e.len() == 1 && f.len() == 1) ||
                                        (e.len() > 1 && e.len() <= f.len())))
}

fn main() {
    let S: String = read();
    let T: String = read();
    println!("{}", if is_matched(&S, &T) { "Yes" } else { "No" })
}