工作技能可以写熟悉ascii码的背诵么?(笑)
use std::io::{self, *};
fn encry(s:Vec<u8>) -> String {
let mut st = String::new();
for i in s {
let c = match i {
48..=56 => i+1,//0 8 -> 1 9
57 => 48,// 9 -> 0
65..=89 => i + 33,//A Y -> b z
90 => 97,//Z -> a
97..=121 => i - 31,//a y -> B Z
122 => 65,//z -> A
_ => i,
};
st.push(char::from(c));
}
st
}
fn decry(s:Vec<u8>) -> String {
let mut st = String::new();
for i in s {
let c = match i {
48 => 57,//0 => 9
49..=57 => i-1,//1 9 -> 0 8
65 => 122,//A -> z
66..=90 => i + 31,//B Z -> a y
97 => 90,//a -> Z
98..=122 => i - 33,//b z -> A
_ => i,
};
st.push(char::from(c));
}
st
}
fn main() {
let stdin = io::stdin();
let mut is_first = true;
for line in stdin.lock().lines() {
let ll = line.unwrap();
let s: Vec<u8> = Vec::from(ll);
if is_first {
println!("{}",encry(s));
is_first = false;
}else{
println!("{}",decry(s));
is_first = true;
}
}
}