結果
問題 |
No.2778 Is there Same letter?
|
ユーザー |
|
提出日時 | 2024-06-16 14:21:49 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 1,354 bytes |
コンパイル時間 | 14,456 ms |
コンパイル使用メモリ | 402,784 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-16 14:22:11 |
合計ジャッジ時間 | 16,012 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
コンパイルメッセージ
warning: unused variable: `n` --> src/main.rs:7:9 | 7 | let n = scan.token::<i32>(); | ^ help: if this is intentional, prefix it with an underscore: `_n` | = note: `#[warn(unused_variables)]` on by default
ソースコード
use std::io; use std::str; fn main() { let mut scan = UnsafeScanner::new(io::stdin().lock()); let n = scan.token::<i32>(); let s = scan.token::<String>(); let mut freq = [0i32; 26]; for c in s.chars() { let char_idx = (c as u8 - b'A') as usize; freq[char_idx] += 1; } for val in freq { if val > 1 { println!("Yes"); return; } } println!("No"); } // I/O template below pub struct UnsafeScanner<R> { reader: R, buf_str: Vec<u8>, buf_iter: str::SplitAsciiWhitespace<'static>, } impl<R: io::BufRead> UnsafeScanner<R> { pub fn new(reader: R) -> Self { Self { reader, buf_str: vec![], buf_iter: "".split_ascii_whitespace(), } } pub fn token<T: str::FromStr>(&mut self) -> T { loop { if let Some(token) = self.buf_iter.next() { return token.parse().ok().expect("Failed parse"); } self.buf_str.clear(); self.reader .read_until(b'\n', &mut self.buf_str) .expect("Failed read"); self.buf_iter = unsafe { let slice = str::from_utf8_unchecked(&self.buf_str); std::mem::transmute(slice.split_ascii_whitespace()) } } } }