結果

問題 No.22 括弧の対応
ユーザー
提出日時 2024-05-14 11:02:56
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 483 bytes
コンパイル時間 28,904 ms
コンパイル使用メモリ 400,524 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-20 09:52:51
合計ジャッジ時間 14,354 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).ok();
	let n: Vec<usize> = s.split_whitespace().flat_map(str::parse).collect();
	s.clear();
	std::io::stdin().read_line(&mut s).ok();
	let mut v = vec![];
	s.chars().enumerate().for_each(|(i, c)| match c {
		'(' => v.push(i + 1),
		_ => {
			if let Some(j) = v.pop() {
				match n[1] {
					x if x == j => println!("{}", i + 1),
					x if x == i + 1 => println!("{}", j),
					_ => {}
				}
			}
		}
	});
}
0