OA2

Course Session Wizard

import java.util.*;
public class Course {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Long launch_day = sc.nextLong();
        Integer freq = sc.nextInt();
        Long enroll_day = sc.nextLong();
        Course test = new Course();
        System.out.println(Arrays.toString(test.courseWizard(launch_day,freq,enroll_day)));
    }
    public Long[] courseWizard(Long launch_day, Integer freq, Long enroll_day){
        Calendar cs = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
        cs.setTimeInMillis(launch_day);
        int dayofweek = cs.get(Calendar.DAY_OF_WEEK);
        while(dayofweek!=2){
            launch_day += 86400*1000;
            cs.setTimeInMillis(launch_day);
            dayofweek = cs.get(Calendar.DAY_OF_WEEK);
        }
        while(enroll_day>launch_day){
            launch_day += 604800*1000*freq;
        }
        Long[] rst = new Long[3];
        rst[0] = launch_day;
        rst[1] = rst[0] + 604800*1000*freq;
        rst[2] = rst[1] + 604800*1000*freq;
        return rst;
    }
}

Coursera Specialization Wizard

import java.util.*;
public class Course2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int row = sc.nextInt();
        int col = sc.nextInt();
        Long[][] ipt = new Long[row][col];
        for(int i=0;i<row;i++){
            for(int j=0;j<col;j++){
                ipt[i][j] = sc.nextLong();
            }
        }
        Long enroll_day = sc.nextLong();
        Course2 test = new Course2();
        System.out.println(Arrays.deepToString(test.courseWizard2(ipt, enroll_day)));
    }
    public Long[][] courseWizard2(Long[][] ipt, Long enroll_day){
        Calendar cs = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
        int row = ipt.length;
        int col = ipt[0].length;
        Long last_end = enroll_day;
        Long[][] rst = new Long[row][2];
        for(int i=0;i<row;i++){
            Long launch_day = ipt[i][0];
            Long freq = ipt[i][1];
            Long duration = ipt[i][2];
            cs.setTimeInMillis(launch_day);
            int dayofweek = cs.get(Calendar.DAY_OF_WEEK);
            while(dayofweek!=2){
                launch_day += 86400*1000;
                cs.setTimeInMillis(launch_day);
                dayofweek = cs.get(Calendar.DAY_OF_WEEK);
            }
            while(enroll_day>launch_day||launch_day<last_end){
                launch_day += 604800*1000*freq;
            }
            rst[i][0] = launch_day;
            rst[i][1] = launch_day + 604800*1000*duration;
            last_end = rst[i][1];
        }
        return rst;
    }
}

results matching ""

    No results matching ""