From 758200be5c2007c722914021302f6c963e856d0f Mon Sep 17 00:00:00 2001 From: SquidSpirit Date: Wed, 20 Aug 2025 22:32:32 +0800 Subject: [PATCH] feat: 3280_convert_date_to_binary --- 3280_convert_date_to_binary/Cargo.lock | 7 +++++++ 3280_convert_date_to_binary/Cargo.toml | 6 ++++++ 3280_convert_date_to_binary/src/lib.rs | 12 ++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 3280_convert_date_to_binary/Cargo.lock create mode 100644 3280_convert_date_to_binary/Cargo.toml create mode 100644 3280_convert_date_to_binary/src/lib.rs diff --git a/3280_convert_date_to_binary/Cargo.lock b/3280_convert_date_to_binary/Cargo.lock new file mode 100644 index 0000000..61dfe86 --- /dev/null +++ b/3280_convert_date_to_binary/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "convert_date_to_binary" +version = "0.1.0" diff --git a/3280_convert_date_to_binary/Cargo.toml b/3280_convert_date_to_binary/Cargo.toml new file mode 100644 index 0000000..4412657 --- /dev/null +++ b/3280_convert_date_to_binary/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "convert_date_to_binary" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/3280_convert_date_to_binary/src/lib.rs b/3280_convert_date_to_binary/src/lib.rs new file mode 100644 index 0000000..35f6b6f --- /dev/null +++ b/3280_convert_date_to_binary/src/lib.rs @@ -0,0 +1,12 @@ +pub struct Solution; + +impl Solution { + pub fn convert_date_to_binary(date: String) -> String { + let [y, m, d]: [i32; 3] = date.split('-') + .map(|num_str| num_str.parse().unwrap()) + .collect::>() + .try_into() + .unwrap(); + format!("{:b}-{:b}-{:b}", y, m, d) + } +}