[等級1]2016年(JAVA)


  • 月から日までは重複構造であるため、キューを使用して
  • を解決する.
    import java.util.*;
    
    class Solution {
        public String solution(int a, int b) {
            Queue<String> q = new LinkedList<>();
            int[] howDay = new int[13];
            
            howDay[0] = 0; 
            howDay[1] = 31; howDay[2] = 29; howDay[3] = 31;
            howDay[4] = 30; howDay[5] = 31; howDay[6] = 30;
            howDay[7] = 31; howDay[8] = 31; howDay[9] = 30;
            howDay[10] = 31; howDay[11] = 30; howDay[12] = 31;
            
            q.offer("FRI"); q.offer("SAT"); q.offer("SUN"); 
            q.offer("MON"); q.offer("TUE"); q.offer("WED");
            q.offer("THU");
            
            int curDate = b;
            for(int i=0; i<a; ++i)
                curDate += howDay[i];
            
            for(int i=1; i<curDate; ++i)
                q.offer(q.poll());
            
            String answer = q.poll();
            return answer;
        }
    }