题解 | #A+B(1)#
A+B(1)
https://ac.nowcoder.com/acm/contest/5652/A
RUST字符串排序
#![allow(dead_code)] use std::io; use std::fmt; #[derive(Debug)] pub struct Inputs { pub v: Vec<String>, } impl Inputs { fn from_vec(ve: Vec<&str>) -> Inputs { let mut v = Vec::new(); for i in 0..ve.len() { v.push(ve[i].to_owned()); } Inputs { v } } fn solve(&mut self) -> () { self.v.sort(); println!("{}", self); } } impl fmt::Display for Inputs { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut i = 0usize; for e in self.v.iter() { write!(f, "{}", e)?; i += 1; if i < self.v.len() { write!(f, ",")?; } } Ok(()) } } pub fn main() { loop { match input() { Some(mut input) => input.solve(), None => break } } } pub fn input() -> Option<Inputs> { let mut input = String::new(); match io::stdin().read_line(&mut input) { Ok(_n) => { let s = input.trim_end(); match s.len() { 0 => None, _ => { let arr: Vec<&str> = s.split(',').collect(); Some(Inputs::from_vec(arr)) } } } Err(error) => panic!("error: {}", error), } }