Relative Frequency by Panda

fn main() {
    for io::stdin().each_line |line| {
        let c = line.slice(0, 1);
        let s = line.slice(2, line.len());

        let n = s.len();
        let r = n - str::replace(s, c, "").len();

        io::println(fmt!("%.6f", (r as float) / (n as float)));
    }
}

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page