Last active
September 7, 2016 16:09
-
-
Save ahomu/fb3b35ee203f020cb774b97313378446 to your computer and use it in GitHub Desktop.
_人人人人人_ > 突然の死 <  ̄Y^Y^Y^Y^Y ̄
This file contains hidden or 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::env; | |
use std::process; | |
const HALF_WIDTH: f32 = 0.5_f32; | |
const FULL_WIDTH: f32 = 1_f32; | |
fn str_repeat(string: &str, count: i16) -> String { | |
(0..count).map(|_| string).collect::<String>() | |
} | |
fn main() { | |
let args: Vec<_> = env::args().collect(); | |
if args.len() < 2 { | |
println!("Usage: {} \"突然の死\"", args[0]); | |
process::exit(1); | |
} | |
let words = &args[1]; | |
let width = words.chars().fold(0_f32, |acc, c| { | |
if c.len_utf8() < 3 { acc + HALF_WIDTH } | |
else { acc + FULL_WIDTH } | |
}); | |
let count = width.ceil() as i16; | |
println!("_人人{}_\n> {} <\n ̄Y{} ̄", | |
str_repeat("人", count), | |
words, | |
str_repeat("^Y", count) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment