結果

問題 No.207 世界のなんとか
ユーザー tmtm
提出日時 2022-11-17 15:53:25
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,142 bytes
コンパイル時間 930 ms
コンパイル使用メモリ 173,336 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 07:31:44
合計ジャッジ時間 1,607 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn getline() -> String {
    let mut a = String::new();
    std::io::stdin().read_line(&mut a).ok();
    return a;
}

fn main() {
    let input = getline();
    let splited: Vec<&str> = input.trim().split(" ").collect();
    let a = splited[0].parse::<u32>().unwrap();
    let b = splited[1].parse::<u32>().unwrap();
    let result = logic(a, b);
    for i in result.iter() {
        println!("{}", i);
    }
}

fn check_three(x: u32) -> bool {
    let s = x.to_string();
    for char in s.chars() {
        if char == '3' {
            return true;
        }
    }
    return false;
}

#[test]
fn test_check_three() {
    let a = check_three(132);
    assert_eq!(a, true);
    let a = check_three(568468);
    assert_eq!(a, false);
}

fn logic(a: u32, b: u32) -> Vec<u32> {
    let mut res: Vec<u32> = vec![];
    for i in a..b+1 {
        if i % 3 == 0 {
            res.push(i);
        } else if check_three(i){
            res.push(i);
        }
    }
    return res;
}

#[test]
fn test_logic() {
    let res = logic(1, 10);
    assert_eq!(res, vec![3, 6, 9]);
    let res = logic(10, 20);
    assert_eq!(res, vec![12, 13, 15, 18]);
}

0