Sunday, December 1, 2013

USACO - Section 1.1 - Friday


import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;

/*
 ID: akshika1
 LANG: JAVA
 TASK: friday
 */
 class friday {

    public static void main(String[] args) throws FileNotFoundException {
        Scanner sc = new Scanner(new File("friday.in"));
        PrintWriter pw = new PrintWriter(new File("friday.out"));

        int N = sc.nextInt();
        int[] days = new int[7];
        int firstday = 0;                 //0= monday, 1=tuesday....6=sunday
        int thirteenth;
        for (int i = 0; i <N; i++) {
           
            //jan
            thirteenth =(firstday + 12)%7;  
            days[thirteenth]++;
            firstday  = (firstday+31)%7;
           
            if((i+1900)%400==0)                  // a leap year
            {                                    //february
            thirteenth =(firstday + 12)%7;  
            days[thirteenth]++;
            firstday  = (firstday+29)%7;
           
            }
            else if((i+1900)%4==0 && (i+1900)%100!=0)               //lead year
            {
            thirteenth =(firstday + 12)%7;  
            days[thirteenth]++;
            firstday  = (firstday+29)%7;
           
            }
            else   //just a noraml year
            {
            thirteenth =(firstday + 12)%7;  
            days[thirteenth]++;
            firstday  = (firstday+28)%7;
           
            }
            //March 31
            thirteenth =(firstday + 12)%7;  
            days[thirteenth]++;
            firstday  = (firstday+31)%7;
           
            //April 30
            thirteenth =(firstday + 12)%7;  
            days[thirteenth]++;
            firstday  = (firstday+30)%7;
           
            //may 31
            thirteenth =(firstday + 12)%7;  
            days[thirteenth]++;
            firstday  = (firstday+31)%7;
           
            //june 30
            thirteenth =(firstday + 12)%7;  
            days[thirteenth]++;
            firstday  = (firstday+30)%7;
           
            //july 31
            thirteenth =(firstday + 12)%7;  
            days[thirteenth]++;
            firstday  = (firstday+31)%7;
           
            //august 31
            thirteenth =(firstday + 12)%7;  
            days[thirteenth]++;
            firstday  = (firstday+31)%7;
           
            //sep 30
            thirteenth =(firstday + 12)%7;  
            days[thirteenth]++;
            firstday  = (firstday+30)%7;
           
            //oct 31
            thirteenth =(firstday + 12)%7;  
            days[thirteenth]++;
            firstday  = (firstday+31)%7;
           
            //novem 30
            thirteenth =(firstday + 12)%7;  
            days[thirteenth]++;
            firstday  = (firstday+30)%7;
           
            //decme 31
            thirteenth =(firstday + 12)%7;  
            days[thirteenth]++;
            firstday  = (firstday+31)%7;
           
           
        }
     
        pw.println(days[5]+" "+days[6]+" "+days[0]+" "+days[1]+" "+days[2]+" "+ days[3]+" "+days[4]);
        pw.close();
             
    }
}

No comments:

Post a Comment