From 3a3c4309d5798f5ed622d06b3f9c97d7f7899727 Mon Sep 17 00:00:00 2001 From: Andrew Guschin Date: Wed, 6 Apr 2022 11:01:50 +0400 Subject: Initial commit --- Cargo.lock | 7 +++++++ Cargo.toml | 8 ++++++++ src/main.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/main.rs diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..41ac3f5 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "coursework-year3" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..69fb7fe --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "coursework-year3" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..3e6e952 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,40 @@ +use std::io::{self, BufRead}; + +fn read_graph(line: String) -> (usize, Vec>) { + let mut chars: Vec = Vec::new(); + for character in line.chars() { + chars.push((character as i32 - 63) as u8); + } + // TODO: spec allows multi-byte vector size + let n = chars[0] as usize; + let bytes = &chars[1..]; + + let mut mat: Vec> = vec![vec![0; n]; n]; + let mut i = 0; + for col in 1..n { + for row in 0..col { + let bit: u8 = bytes[i / 6] >> (5 - i % 6) & 1; + mat[row][col] = bit; + mat[col][row] = bit; + i += 1; + } + } + return (n, mat); +} + +fn main() { + let stdin = io::stdin(); + + for line in stdin.lock().lines() { + let (n, mat) = read_graph(line.unwrap()); + + println!("Vector of size {}", n); + for row in 0..n { + for col in 0..n { + print!("{} ", mat[row][col]); + } + println!(""); + } + } + +} -- cgit v1.2.3