Created
December 28, 2014 15:09
-
-
Save veer66/8c5db123c0d8e10a332c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pw = nil | |
pc = 0 | |
$stdin.each do |line| | |
line.chomp! | |
w, year, c1, c2 = line.split(/\t/) | |
if not pw.nil? and pw != w | |
puts "#{pw}\t#{pc}" | |
pw = nil | |
end | |
c1 = c1.to_i | |
if pw.nil? | |
pw = w | |
pc = c1 | |
else | |
pc += c1 | |
end | |
end | |
if not pw.nil? | |
puts "#{pw}\t#{pc}" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io; | |
fn main() { | |
let mut pw: String = String::new(); | |
let mut pc: int = 0; | |
let mut started = false; | |
for line in io::stdin().lock().lines() { | |
let line = line.unwrap(); | |
let mut split = line.split_str("\t"); | |
let _w = split.next().unwrap(); | |
let w = String::from_str(_w); | |
split.next(); | |
let _c:Option<int> = split.next().unwrap().parse(); | |
let c = _c.unwrap(); | |
if started && pw != w { | |
println!("{}\t{}", pw, pc); | |
started = false; | |
} | |
if !started { | |
started = true; | |
pw = w; | |
pc = c; | |
} else { | |
pc += c; | |
} | |
} | |
if started { | |
println!("{}\t{}", pw, pc); | |
} | |
} |
Ruby
real 90m47.088s
user 94m15.470s
sys 1m20.872s
Rust
real 11m9.995s
user 13m12.904s
sys 0m59.891s
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank @awesomeintheory and @bstrie. Now my program written in #Rust very fast just by adding "--release" to cargo. ^^