結果
| 問題 | No.539 インクリメント | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-10-11 15:20:21 | 
| 言語 | Rust (1.83.0 + proconio) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 36 ms / 2,000 ms | 
| コード長 | 2,852 bytes | 
| コンパイル時間 | 13,575 ms | 
| コンパイル使用メモリ | 378,232 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-17 09:40:38 | 
| 合計ジャッジ時間 | 13,874 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 3 | 
ソースコード
#[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 mid = add1(&s_level.chars().collect::<Vec<_>>());
        s[0..l]
            .iter()
            .cloned()
            .chain(mid.iter().cloned())
            .chain(s[r + 1..].iter().cloned())
            .collect()
    } else {
        // no digit
        s.iter().cloned().collect()
    }
}
fn add1(n: &[char]) -> Vec<char> {
    let mut res = Vec::new();
    let mut up = true;
    for &c in n.iter().rev() {
        if !up {
            res.push(c);
        } else {
            let d = c.to_digit(10).unwrap();
            if d == 9 {
                res.push('0');
            } else {
                res.push(('0' as u8 + d as u8 + 1) as char);
                up = false;
            }
        }
    }
    if up {
        res.push('1');
    }
    res.iter().cloned().rev().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));
    }
}
            
            
            
        