编辑代码



class Main {

    static class Player{
        String job = "a";
        int year = 2023;
        int base = 2700;
        String[] unDay = new String[30];
        public void init(){
            unDay[8] = "1";
            unDay[9] = "1";
            unDay[10] = "1";
            unDay[0] = "1";
            unDay[30] = "1";
            unDay[20] = "1";
            unDay[21] = "1";
        }
        public String getUnDayRemark(){
            String remark = "";
            List<int> cache = new ArrayList();
            for(int i=0;i<unDay.lenght;i++){
                if(unDay[i]!="0"){
                    int day = ((int)i)+1;
                    cache.add(day);
                }
            }
            //至算法
            int starDay = -1;
            int offset = 0;
            for(int i = 0;i<cache.size();i++){
                //初始化
                if(starDay == -1) {
                    starDay = cache.get(i);
                    offset = 0;
                    continue;
                }
                offset++;
                //1日 == 偏移量 - 当前存储的哪一天
                //1日 == 偏移1 - 2日
                if(starDay == offset - cache.get(i)){
                    continue;
                    //超过一个以上就可以用至
                }else{
                    if(offset == 1){
                        remark += starDay + "日";
                    }
                    if(offset > 1){
                        remark += starDay +"日至"+offset+starDay+"日";
                    }
                }
                //判断是否结束添加、
                if(cache.size()-1 != i){
                    remark+="、";
                }
            }
        }
    
    }

    public static void main(String[] args) {
        Player p = new Player();
        p.init();
        System.out.println(p.getUnDayRemark());
    }
    
    //根据人来设置备注
	public static String getRemark(Player player){
        


		return "";
	}

}