Skip to content

Instantly share code, notes, and snippets.

@nulltier
Last active August 27, 2022 23:20
Show Gist options
  • Save nulltier/21dd3e2f6a5ecb4469993bcef992aaa3 to your computer and use it in GitHub Desktop.
Save nulltier/21dd3e2f6a5ecb4469993bcef992aaa3 to your computer and use it in GitHub Desktop.
Rust template for the HackerRank tasks
// Enter your code here
use std::io;
#[derive(Debug)]
enum Case {
TwoLines(String, String)
}
fn readStdin() -> Vec<String> {
let mut result: Vec<String> = Vec::new();
loop {
let mut input = String::new();
match io::stdin().read_line(&mut input) {
Ok(n) => {
if n == 0 {
break;
}
}
Err(e) => {
eprintln!("{e}");
}
}
result.push(input.clone());
}
result
}
fn readCases() -> Vec<Case> {
let lines = readStdin();
let len = lines.len();
let mut result: Vec<Case> = Vec::new();
let mut prev: &str = "";
for (i, line) in lines.iter().skip(1).enumerate() {
let i_after_skip = i - 1;
match i_after_skip % 2 {
1 => {
prev = line;
}
0 => {
result.push(
Case::TwoLines(prev.trim().to_string(), line.trim().to_string())
);
}
_ => {
panic!("Impossible");
}
}
}
result
}
fn solution(case: Case) {
}
fn lex_minimal (lft: String, rht: String) -> String {
format!("{}{}", lft, rht)
}
fn main() -> io::Result<()> {
let cases = readCases();
for case in cases {
match case {
Case::TwoLines(first, second) => {
println!("result: {}", lex_minimal(first, second));
}
_ => {
panic!("Unknown case")
}
}
}
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment