We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
usestd::env;usestd::fs::File;usestd::io::{self,BufRead,Write};/* * Complete the 'timeConversion' function below. * * The function is expected to return a STRING. * The function accepts STRING s as parameter. */fntimeConversion(s:&str)->String{letchars:Vec<char>=s.chars().collect();letam_pm=chars[8]=='A';letmid=chars[0]=='1'&&chars[1]=='2';returnmatcham_pm{true=>{ifmid{String::from({format!("00{}",chars.iter().skip(2).take(6).collect::<String>())})}else{String::from({chars.iter().take(8).collect::<String>()})}},false=>{ifmid{String::from({chars.iter().take(8).collect::<String>()})}else{letfirst_two=chars[0].to_digit(10).unwrap()*10+chars[1].to_digit(10).unwrap()+12;iffirst_two==24{first_two==0;}String::from({format!("{:0>2}{}",first_two,chars.iter().skip(2).take(6).collect::<String>())})}}}}fnmain(){letstdin=io::stdin();letmutstdin_iterator=stdin.lock().lines();letmutfptr=File::create(env::var("OUTPUT_PATH").unwrap()).unwrap();lets=stdin_iterator.next().unwrap().unwrap();letresult=timeConversion(&s);writeln!(&mutfptr,"{}",result).ok();}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Time Conversion
You are viewing a single comment's thread. Return to all comments →
I touch memory,
Rust