본문 바로가기

C/C++

[Rust] 369게임

//three six nine. 369 game
fn main() {
  for n in 1..100 {
    let mut cur_num: u32 = n;
    let mut clap_cnt: u32 = 0;

    while cur_num > 0 {
      let cur_x:u32 = cur_num % 10;

      clap_cnt += match cur_x {
        3 | 6 | 9 => 1,
        _ => 0
      };

      cur_num /= 10;
    }

    if clap_cnt > 0 {
      for _c in 0..clap_cnt {
        print!("clap! ");
      }
      print!("\n");
    } else {
      println!("{}", n);
    }
  }
}

 

연습