beephsupreme

Untitled

Sep 6th, 2022
1,496
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.43 KB | Source Code | 0 0
  1. // use std::fmt::Write;
  2. use std::collections::btree_map::BTreeMap;
  3.  
  4. type INT = u64;
  5.  
  6. pub fn main() {
  7.     let buf_size: usize = 1000000;
  8.     let mut input = String::with_capacity(buf_size);
  9.     // let mut output = String::with_capacity(buf_size);
  10.     std::io::stdin().read_line(&mut input).unwrap();
  11.     input.pop();
  12.     let n = input.len();
  13.     let mut odd_count: i64 = 0;
  14.     let mut middle = '#';
  15.     let mut alphabet: BTreeMap<char, INT> = BTreeMap::from
  16.         ([('A', 0), ('B', 0), ('C', 0), ('D', 0), ('E', 0), ('F', 0),
  17.             ('G', 0), ('H', 0), ('I', 0), ('J', 0), ('K', 0), ('L', 0),
  18.             ('M', 0), ('N', 0), ('O', 0), ('P', 0), ('Q', 0), ('R', 0),
  19.             ('S', 0), ('T', 0), ('U', 0), ('V', 0), ('W', 0), ('X', 0),
  20.             ('Y', 0), ('Z', 0)]);
  21.  
  22.     for c in input.chars() {
  23.         *alphabet.entry(c).or_insert(0) += 1;
  24.     }
  25.  
  26.     for (_, v) in &alphabet {
  27.         if v % 2 != 0 { odd_count += 1 }
  28.     }
  29.  
  30.     if odd_count > 1 {
  31.         println!("NO SOLUTION");
  32.         return;
  33.     }
  34.     if n == 1 {
  35.         for (c, v) in alphabet {
  36.             if v == 1 {
  37.                 println!("{}", c);
  38.             }
  39.         }
  40.         return;
  41.     }
  42.     if n % 2 == 1 {
  43.         for (c, v) in alphabet {
  44.             if v % 2 == 1 {
  45.                 middle = c;
  46.             }
  47.         }
  48.     }
  49.     for (_, mut v) in alphabet.clone() {
  50.         v = v / 2;
  51.     }
  52.  
  53.     println!("{}", input.len());
  54. }
Advertisement