背景
用最少的字符来表现下图所示bool
实现代码
/**
* 时间范围内是否投放控制(周一至周日,0点至24点)
*
* @Date 2021/2/1 9:40
**/
public class DateRange {
private static final int WEEK_SIZE = 7;
private static final int LEN = 42;
private static final int WEEK_BIT_LEN = 6 * 4; // 0 ~ 24 小时,每4个小时一组,一周
/**
* 有序二维数组,初始化为空数组
*
* @param
* @return
* @Date 2021/2/2 18:02
**/
private static List<List<String>> index = new ArrayList(WEEK_SIZE * WEEK_BIT_LEN);
static {
for (int i = 0; i < WEEK_SIZE * WEEK_BIT_LEN; i++) {
index.add(new ArrayList<>());
}
}
public static void main(String[] args) throws Exception {
addIndex("ffffffffffffffffffffffffffffffffffffffffff", "全周全天投放");
addIndex("fffffffffffffffffffffffffffffffffffffff000", "周一0点至12点不投放");
addIndex("fffffffffffffffffffffffffffffffff000ffffff", "周二0点至12点不投放");
addIndex("000000ffffffffffffffffffffffffffffffffffff", "周日全天不投放");
addIndex("ffffffffffff000000000000000000000000000000", "周一到周五全天不投放");
int week = 1;
int hour = 10;
System.out.println("周" + week + "," + hour + "点所有可投放项,预估的结果:全周全天投放, 周二0点至12点不投放, 周日全天不投放");
System.out.println("周" + week + "," + hour +