結果
| 問題 | No.539 インクリメント |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-10-11 15:08:11 |
| 言語 | Rust (1.92.0 + proconio + num) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,588 bytes |
| 記録 | |
| コンパイル時間 | 13,074 ms |
| コンパイル使用メモリ | 384,452 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-17 09:40:23 |
| 合計ジャッジ時間 | 14,703 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 1 RE * 2 |
ソースコード
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
mod util {
use std::io::stdin;
use std::str::FromStr;
use std::fmt::Debug;
#[allow(dead_code)]
pub fn line() -> String {
let mut line: String = String::new();
stdin().read_line(&mut line).unwrap();
line.trim().to_string()
}
#[allow(dead_code)]
pub fn get<T: FromStr>() -> T
where
<T as FromStr>::Err: Debug,
{
let mut line: String = String::new();
stdin().read_line(&mut line).unwrap();
line.trim().parse().unwrap()
}
#[allow(dead_code)]
pub fn gets<T: FromStr>() -> Vec<T>
where
<T as FromStr>::Err: Debug,
{
let mut line: String = String::new();
stdin().read_line(&mut line).unwrap();
line.split_whitespace()
.map(|t| t.parse().unwrap())
.collect()
}
#[allow(dead_code)]
pub fn get2<T: FromStr, U: FromStr>() -> (T, U)
where
<T as FromStr>::Err: Debug,
<U as FromStr>::Err: Debug,
{
let mut line: String = String::new();
stdin().read_line(&mut line).unwrap();
let mut iter = line.split_whitespace();
(
iter.next().unwrap().parse().unwrap(),
iter.next().unwrap().parse().unwrap(),
)
}
}
#[allow(unused_macros)]
macro_rules! debug {
($x: expr) => {
println!("{}: {:?}", stringify!($x), $x)
}
}
fn leve_up(s: &[char]) -> String {
let r = (0..s.len()).rev().find(|&i| s[i].is_digit(10));
if let Some(r) = r {
let l = (0..r + 1)
.rev()
.take_while(|&i| s[i].is_digit(10))
.last()
.unwrap();
let s_level = s[l..r + 1].iter().cloned().collect::<String>();
let next_level: usize = s_level.parse::<usize>().unwrap() + 1;
let mut mid = next_level.to_string();
if s_level.len() > mid.len() {
mid = (0..s_level.len() - mid.len())
.map(|_| '0')
.chain(mid.chars())
.collect();
}
s[0..l]
.iter()
.cloned()
.chain(mid.chars())
.chain(s[r + 1..].iter().cloned())
.collect()
} else {
// no digit
s.iter().cloned().collect()
}
}
fn main() {
let n: usize = util::get();
for _ in 0..n {
let line = util::line();
let s = line.chars().collect::<Vec<char>>();
println!("{}", leve_up(&s));
}
}