输入两个骰子,判断二者是否等价。每个骰子用6个字母表示,如图4-7所示。
例如rbgggr和rggbgr分别表示如图4-8所示的两个骰子。二者是等价的,因为图4-8(a)所示的骰子沿着竖直轴旋转90°之后就可以得到图4-8(b)所示的骰子。
样例:
rggbgr
rbgggr
same
解法:
use std::io;
/*
1
3 2 4 5 1在顶上
6
2
3 6 4 1 2在顶上
5
3
5 6 2 1 3在顶上
4
4
2 6 5 1 4在顶上
3
5
4 6 3 1 5在顶上
2
6
3 5 4 2 6在顶上
1
上面每种,都要沿竖轴旋转4次,所以一共24种情况
*/
fn main() {
let mut buf = String::new();
io::stdin().read_line(&mut buf).unwrap();
let s = buf.trim().to_string();
let mut buf = String::new();
io::stdin().read_line(&mut buf).unwrap();
let t = buf.trim().to_string();
let orders = [
[1, 2, 3, 4, 5, 6],
[2, 6, 3, 4, 1, 5],
[3, 6, 5, 2, 1, 4],
[4, 6, 2, 5, 1, 3],
[5, 6, 4, 3, 1, 2],
[6, 5, 3, 4, 2, 1],
];
for i in 0..6 {
let mut order = orders[i];
for _ in 0..4 {
let mut newt = String::new();
order = rotate(order);
for j in 0..6 {
let c = t.chars().nth(order[j] - 1).unwrap();
newt.push(c);
}
if s == newt {
println!("same");
return;
}
}
}
println!("not same");
}
//沿着竖轴旋转
fn rotate(order: [usize; 6]) -> [usize; 6] {
let mut neworder = order;
neworder[2 - 1] = order[3 - 1];
neworder[3 - 1] = order[5 - 1];
neworder[4 - 1] = order[2 - 1];
neworder[5 - 1] = order[4 - 1];
return neworder;
}