結果
| 問題 |
No.729 文字swap
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-05-04 15:10:04 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| コード長 | 789 bytes |
| コンパイル時間 | 11,300 ms |
| コンパイル使用メモリ | 394,180 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-22 18:59:23 |
| 合計ジャッジ時間 | 12,217 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 |
ソースコード
fn main() -> Result<(), std::io::Error> {
let mut s = String::new();
std::io::stdin().read_line(&mut s).ok();
let input_str = s.trim().to_string();
s.clear();
std::io::stdin().read_line(&mut s).ok();
let ids: Vec<usize> =
s.trim().split_whitespace().map(|e| e.parse::<usize>().ok().unwrap()).collect();
let tmp0 = input_str.chars().nth(ids[0]).unwrap();
let tmp1 = input_str.chars().nth(ids[1]).unwrap();
let str_converted: String =
input_str.chars().enumerate().map(|e| {
if e.0 == ids[0] {
return tmp1;
} else if e.0 == ids[1] {
return tmp0;
} else {
return e.1;
}
}).collect();
println!("{}", str_converted);
Ok(())
}