daily pastebin goal
10%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use std::io;
  2. use std::collections::HashMap;
  3. use std::collections::hash_map::Entry;
  4.  
  5. #[allow(dead_code)]
  6.  
  7. fn to_str(values: [i32; 100]) -> String {
  8.     let mut sorted: Vec<i32> = Vec::new();
  9.     for i in 0 .. 100{
  10.         if values[i] == 0 {continue}
  11.         for _ in 0 .. values[i as usize] {sorted.push(i as i32)}
  12.     }
  13.     sorted
  14.         .iter()
  15.         .map(i32::to_string)
  16.         .collect::<Vec<_>>()
  17.         .join(" ")
  18. }
  19.  
  20. fn main() {
  21.     let reader = io::stdin();
  22.     let mut input = String::new();
  23.     let mut cases = HashMap::<i32, Vec<String>>::new();
  24.    
  25.     reader.read_line(&mut input).expect("fail to readline");
  26.     let size = input.parse::<usize>().expect("a number is expected");
  27.  
  28.     for _ in 0 .. size {
  29.         input.clear();
  30.         reader.read_line(&mut input).expect("fail to readline");
  31.         let new_elem: Vec<&str> = input
  32.             .split_whitespace()
  33.             .collect();
  34.        
  35.         let (index, value) = (new_elem[0].parse::<i32>().expect("a number is expected"),
  36.                               new_elem[1].to_owned().clone());
  37.        
  38.         match cases.entry(index) {
  39.             Entry::Vacant(e) => e.insert(vec![value]),
  40.             Entry::Occupied(e) => e.into_mut()
  41.         };
  42.     }
  43. }
RAW Paste Data
Top