개발공부
우당탕탕 RUST 도전기 (1)
JHKim93
2024. 6. 23. 23:53
FE 개발자의 막무가내 Rust 도전기
- 8진수 2진수 (#1212)
use std::io::{self, BufRead};
pub fn main() {
let mut input= String::new();
io::stdin().lock().read_line(&mut input).unwrap();
let input = input.trim();
let mut res = String::new();
let arr = ["000", "001", "010", "011", "100", "101", "110", "111"];
for o_num in input.chars() {
res.push_str(change_o_to_b(o_num, arr));
}
if res == "000" {
println!("{}", 0)
} else {
println!("{}", res.trim_start_matches("0"));
}
}
fn change_o_to_b(oNum: char, binArr: [&str; 8])-> &str {
let idx = oNum.to_digit(8).unwrap() as usize;
binArr[idx]
}
- DNA 해독 (#1672)
use std:: io::{self, BufRead};
pub fn main() {
let mut input = io::stdin().lock().lines();
let N: i32 = input.next().unwrap().unwrap().parse().unwrap();
let yumgi: i32 = input.next().unwrap().unwrap();
let table = [0,A,C,A,G,0,T,0,A,C,0,0,G,0,0,0,T];
let mut res;
for i in (1..=N).rev() {
}
println!("{}",max_val);
println!("{}",max_idx);
}
- 주사위 세개 (#2480)
use std::{cmp::max, io::{self, BufRead}};
pub fn main() {
let mut input= String::new();
io::stdin().lock().read_line(&mut input).unwrap();
let numbers: Vec<i32> = input
.split_whitespace() // 공백을 기준으로 분할
.map(|s| s.parse().unwrap()) // 각 부분 문자열을 숫자로 변환
.collect(); // 결과를 벡터에 수집
if numbers[0] == numbers[1] && numbers[1] == numbers[2] {
println!("{}", numbers[0] * 1000 + 10000);
} else if numbers[0] == numbers[1] || numbers[0] == numbers[2] {
println!("{}", (numbers[0] * 100 + 1000));
} else if numbers[1] == numbers[2] {
println!("{}", (numbers[1] * 100 + 1000));
} else {
println!("{}", max(max(numbers[0], numbers[1]), numbers[2]) * 100);
}
}
- 최대값 (#2562)
use std:: io::{self, BufRead};
pub fn main() {
let mut input = io::stdin().lock().lines();
let mut max_val = 1;
let mut max_idx = 1;
for i in 0..9 {
let num: i32 = input.next().unwrap().unwrap().parse().unwrap();
if num > max_val {
max_val = num;
max_idx = i + 1
}
}
println!("{}",max_val);
println!("{}",max_idx);
}