Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Code LNM 24 : Reverse Me!
- // Author : warks
- use std::io::{BufWriter, stdin, stdout, Write};
- #[derive(Default)]
- struct Scanner {
- buffer: Vec<String>
- }
- impl Scanner {
- fn next<T: std::str::FromStr>(&mut self) -> T {
- loop {
- if let Some(token) = self.buffer.pop() {
- return token.parse().ok().expect("Failed parse");
- }
- let mut input = String::new();
- stdin().read_line(&mut input).expect("Failed read");
- self.buffer = input.split_whitespace().rev().map(String::from).collect();
- }
- }
- }
- fn main() {
- let mut scan = Scanner::default();
- let out = &mut BufWriter::new(stdout());
- let t = scan.next::<usize>();
- for _ in 0..t {
- let n = scan.next::<usize>();
- let mut word = scan.next::<String>().chars().collect::<Vec<_>>();
- word = if word.len() & 1 == 1 { word.into_iter().rev().collect() } else { word };
- word[0] = word[0].to_uppercase().collect::<Vec<_>>()[0];
- write!(out, "{} ", word.into_iter().collect::<String>()).ok();
- for i in 1..n {
- word = scan.next::<String>().chars().collect::<Vec<_>>();
- word = if word.len() & 1 == 1 { word.into_iter().rev().collect() } else { word };
- write!(out, "{}", word.into_iter().collect::<String>()).ok();
- write!(out, "{}", if i + 1 == n { '\n' } else { ' ' }).ok();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement