Skip to content

Instantly share code, notes, and snippets.

@PetrGlad
Last active December 11, 2017 14:30
Show Gist options
  • Save PetrGlad/7e0aff8673ca448aaa761bafe74c58df to your computer and use it in GitHub Desktop.
Save PetrGlad/7e0aff8673ca448aaa761bafe74c58df to your computer and use it in GitHub Desktop.
fn art_slice(ln: &str, step: usize, idx: usize) -> &str {
let ofs = step * idx;
&ln[ofs..(ofs + step)]
}
fn ch_index(ch: char) -> usize {
let lookup_ch = if 'A' <= ch && ch <= 'Z' { ch } else { '?' };
"ABCDEFGHIJKLMNOPQRSTUVWXYZ?".chars().position(|x| x == lookup_ch).unwrap()
}
fn main() {
let rows = vec![
" # ## ## ## ### ## ## # # ### ## # # # # # ### # ## # ## ## ### # # # # # # # # # # ### ###",
"# # # # # # # # # # # # # # # # # ### # # # # # # # # # # # # # # # # # # # # # # # #",
"### ## # # # ## ## # # ### # # ## # ### # # # # ## # # ## # # # # # # ### # # # #",
"# # # # # # # # # # # # # # # # # # # # # # # # # # ## # # # # # # # # ### # # # # #",
"# # ## # ## ### # ## # # ### # # # ### # # # # # # # # # ## # ### # # # # # # ### ."
];
let t = "PIZZAPIZZA\n";
let l = 4;
let h = 5;
// -------------------------------
for ln in rows {
for c in t.to_uppercase().chars() {
print!("{}", art_slice(&ln.to_string(), l, ch_index(c)));
}
println!()
}
}
use std::io;
macro_rules! parse_input {
($x:expr, $t:ident) => ($x.trim().parse::<$t>().unwrap())
}
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
fn main() {
let mut input_line = String::new();
io::stdin().read_line(&mut input_line).unwrap();
let l = parse_input!(input_line, usize);
let mut input_line = String::new();
io::stdin().read_line(&mut input_line).unwrap();
let h = parse_input!(input_line, i32);
let mut input_line = String::new();
io::stdin().read_line(&mut input_line).unwrap();
let t = input_line.trim_right().to_string();
let t_upper = t.to_uppercase();
for i in 0..h as usize {
let mut input_line = String::new();
io::stdin().read_line(&mut input_line).unwrap();
let row = input_line.trim_right().to_string();
eprintln!("row={:?}", row);
for c in t_upper.chars() {
print!("{:<l$}", art_slice(&row, l, ch_index(c)), l=l);
}
println!();
}
// Write an action using println!("message...");
eprintln!("t={:?}", t);
eprintln!("l={:?} h={:?}", l, h);
}
fn art_slice(ln: &str, step: usize, idx: usize) -> String {
ln.chars().skip(step * idx).take(step).collect()
}
fn ch_index(ch: char) -> usize {
let lookup_ch = if 'A' <= ch && ch <= 'Z' { ch } else { '?' };
"ABCDEFGHIJKLMNOPQRSTUVWXYZ?".chars().position(|x| x == lookup_ch).unwrap()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment