use std::io::{self, prelude::*}; #[derive(Debug)] pub struct Scanner { reader: R, buf: String, pos: usize, } impl Scanner where R: BufRead, { pub fn new(reader: R) -> Scanner { Scanner { reader, buf: String::new(), pos: 0, } } pub fn next(&mut self) -> io::Result<&str> { let start = loop { match self.rest().find(|c| c != ' ') { Some(i) => break i, None => self.fill_buf()?, } }; self.pos += start; let len = self.rest().find(' ').unwrap_or(self.rest().len()); let s = &self.buf[self.pos..][..len]; // self.rest()[..len] self.pos += len; Ok(s) } fn rest(&self) -> &str { &self.buf[self.pos..] } fn fill_buf(&mut self) -> io::Result<()> { self.buf.clear(); self.pos = 0; let read = self.reader.read_line(&mut self.buf)?; if read == 0 { return Err(io::ErrorKind::UnexpectedEof.into()); } if *self.buf.as_bytes().last().unwrap() == b'\n' { self.buf.pop(); } Ok(()) } } fn main() -> io::Result<()> { let stdin = std::io::stdin(); let reader = stdin.lock(); let mut scanner = Scanner::new(reader); let stdout = std::io::stdout(); let mut writer = std::io::BufWriter::new(stdout.lock()); let s = scanner.next()?; let ans = s.chars().rev().collect::(); writeln!(writer, "{}", ans) }