結果

問題 No.1469 programing
ユーザー uw_yu1rabbituw_yu1rabbit
提出日時 2021-04-09 21:30:43
言語 Rust
(1.77.0)
結果
AC  
実行時間 214 ms / 3,000 ms
コード長 2,801 bytes
コンパイル時間 2,398 ms
コンパイル使用メモリ 149,116 KB
実行使用メモリ 46,452 KB
最終ジャッジ日時 2023-09-07 09:59:52
合計ジャッジ時間 4,014 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 7 ms
4,380 KB
testcase_09 AC 10 ms
4,384 KB
testcase_10 AC 9 ms
4,384 KB
testcase_11 AC 19 ms
4,380 KB
testcase_12 AC 14 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 26 ms
5,040 KB
testcase_15 AC 15 ms
4,448 KB
testcase_16 AC 24 ms
5,760 KB
testcase_17 AC 214 ms
46,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//use proconio::input;
fn main() {
    let t = std::io::stdin();
    let mut read = snio::Reader::new(t.lock());
    let s = read.string();
    let s:Vec<_> = s.chars().collect();
    let mut t = Vec::new();
    let mut ans = Vec::new();
    for i in 0..s.len() {
        if t.len() > 0 && s[i] != *t.last().unwrap() {
            ans.push(t.pop().unwrap());
            t.push(s[i]);
        }else if t.len() > 0 && s[i] ==*t.last().unwrap(){
            continue;
        }else {
            t.push(s[i]);
        }
    }
    if t.len() > 0 && (ans.len() == 0 || t[0] != ans[ans.len() - 1]) {
        ans.push(t.pop().unwrap());
    }
   // println!("{:?}, {:?}",t,ans);
    for i in 0..ans.len() {
        if i < ans.len() - 1 {
            print!("{}", ans[i]);
        }else{
            println!("{}",ans[i]);
        }
    }
}

#[allow(dead_code)]
pub mod snio {
    pub struct Reader<R: std::io::BufRead> {
        reader: R,
        buf: std::collections::VecDeque<String>,
    }

    impl<R: std::io::BufRead> Reader<R> {
        pub fn new(reader: R) -> Self {
            Self {
                reader,
                buf: std::collections::VecDeque::new(),
            }
        }
        fn load(&mut self) {
            while self.buf.is_empty() {
                let mut s = String::new();
                let length = self.reader.read_line(&mut s).unwrap();
                if length == 0 {
                    break;
                }
                self.buf.extend(s.split_whitespace().map(|s| s.to_owned()));
            }
        }
        pub fn string(&mut self) -> String {
            self.load();
            self.buf.pop_front().unwrap_or_else(|| panic!("input ended"))
        }
        pub fn char(&mut self) -> char {
            let string = self.string();
            let mut chars = string.chars();
            let res = chars.next().unwrap();
            assert!(chars.next().is_none(), "invalid input!");
            res
        }
        pub fn chars(&mut self) -> Vec<char> {
            self.read::<String>().chars().collect()
        }
        pub fn read<T: std::str::FromStr>(&mut self) -> T
            where
                <T as ::std::str::FromStr>::Err: ::std::fmt::Debug,
        {
            self.string().parse::<T>().expect("Failed to parse the input.")
        }
    }
    macro_rules! definition_of_reader_of_numbers {
            ($($ty:tt,)*) => {
                impl <R:std::io::BufRead> Reader<R> {
                    $(
                    #[inline]
                    pub fn $ty (&mut self) -> $ty {
                        self.read::<$ty>()
                    }
                    )*
                }
            }
        }
    definition_of_reader_of_numbers! {
        u8,u16,u32,u64,usize,
        i8,i16,i32,i64,isize,
    }
}
0