diff options
| -rw-r--r-- | Cargo.lock | 7 | ||||
| -rw-r--r-- | Cargo.toml | 8 | ||||
| -rw-r--r-- | src/main.rs | 40 |
3 files changed, 55 insertions, 0 deletions
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<Vec<u8>>) { + let mut chars: Vec<u8> = 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<u8>> = 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!(""); + } + } + +} |