TCHS-12-550

Problem Statement

    

Let's consider a standard six-sided die. Each side contains a distinct number between 1 and 6. We can represent a single die as a sequence of 6 digits in the following order: the number on its top side, bottom side, left, right, front and back sides. You are given a String[] givenDice, each element of which represents a single die in the described format.

Your task is to determine the number of distinct dice in givenDice. Two dice are considered equal if they can be rotated in such a way that the numbers on the corresponding sides are all equal.

Definition

    
Class: DistinctDice
Method: getDistinct
Parameters: String[]
Returns: int
Method signature: int getDistinct(String[] givenDice)
(be sure your method is public)
    
 

Constraints

- givenDice will contain between 1 and 50 elements, inclusive.
- Each element of givenDice will contain exactly 6 characters.
- Each character of each element of givenDice will be a digit between '1' and '6', inclusive.
- Within each element of givenDice, all characters will be distinct.

Examples

0)  
    
{"123456","654321"}
 
Returns: 1
 
 
1)  
    
{"145326","154236","216543"}
 
Returns: 3
 
 
2)  
    
{"165324"}
 
Returns: 1
 
 
3)  
    
{"546231", "245631", "531462", "524631", "614235", "415623", "423651", "316254", "432165", "316452", "135426", "643512"}
 
Returns: 10
 
 
import java.util.*;

public class DistinctDice {
	
	Set<String> dice = new HashSet<String>();
	int[] lt = {2, 3, 1, 0, 4, 5};
	int[] lf = {0, 1, 5, 4, 2, 3};

	public int getDistinct(String[] givenDice) {
		int sum = 0;
		for (String s : givenDice)
			if (!dice.contains(s)) {
				rotate(s);
				sum++;
			}
		return sum;
	}
	
	private void rotate(String s) {
		if (dice.contains(s))
			return;
		dice.add(s);
		char[] c1 = new char[6];
		char[] c2 = new char[6];
		for (int i = 0; i < 6; i++) {
			c1[i] = s.charAt(lt[i]);
			c2[i] = s.charAt(lf[i]);
		}
		rotate(new String(c1));
		rotate(new String(c2));
	}

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值