Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::io;
- use std::io::Write;
- use std::process;
- use std::collections::HashSet;
- fn main() {
- // Prompt for user input
- print!("Input a number: ");
- let _ = io::stdout().flush();
- // Receive user input
- let mut input = String::new();
- io::stdin()
- .read_line(&mut input)
- .expect("failed to read from stdin");
- // Parse the number
- let n = match input.trim().parse::<u32>() {
- Ok(i) => i,
- Err(_) => {
- println!("Invalid integer");
- // Exit the program with abnormal status code
- process::exit(1);
- }
- };
- let x: i32 = 10;
- for i in 1..(x.pow(n)) {
- /* Convert number to an iterator of char.
- Then, insert char to set. */
- let num_string = i.to_string();
- let mut chars = num_string.chars();
- let mut set = HashSet::new();
- let mut c = chars.next();
- while c != None {
- set.insert(c);
- c = chars.next();
- }
- // Get the digit number of i
- let mut digit = 0;
- let mut j = i;
- while j > 0 {
- j = j / 10;
- digit += 1;
- }
- // Check whether i fits our criteria
- if set.len() as i32 >= digit {
- // Show i in console
- print!("{} ", i);
- }
- }
- // Print tailing newline
- println!("");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement