/** This post is for archiving of the problem. **/

Problem:
Dominical (dominic.in)

Dominical letters are letters A, B, C, D, E, F and G assigned to days in a cycle of seven with the letter A always set against 1 January as an aid for finding the day of the week of a given calendar date and in calculating Easter.
A common year is assigned the dominical letter of its first Sunday. For example 2003 has January 5 as its first Sunday, so it has dominical letter E.
In leap years, the leap day may or may not have a dominical letter. In the original 1582 Catholic version, it did, but in the 1752 Anglican version it did not. The Catholic version caused February to have 29 days by doubling the sixth day before 1 March, inclusive, because 24 February in a common year is marked "duplex", thus both halves of the doubled day had a dominical letter of F. The Anglican version added a day to February that did not exist in common years, 29 February, thus it did not have a dominical letter of its own.
In either case, all other dates have the same dominical letter every year, but the days of the weeks of the dominical letters change within a leap year before and after the intercalary day, 24 February or 29 February. Hence leap years have two dominical letters: the first for January and most or all of February and the second for March to December. The second dominical letter is the dominical letter that the year would have if it were not a leap year and the dates in March to December have the same days of the week.
The dominical letter of a year determines the days of week in its calendar:
· A common year starting on Sunday
· B common year starting on Saturday
· C common year starting on Friday
· D common year starting on Thursday
· E common year starting on Wednesday
· F common year starting on Tuesday
· G common year starting on Monday
· AG leap year starting on Sunday
· BA leap year starting on Saturday
· CB leap year starting on Friday
· DC leap year starting on Thursday
· ED leap year starting on Wednesday
· FE leap year starting on Tuesday
· GF leap year starting on Monday

Sample Input:

2008
2001
2005
2003
2010

Sample Output:

FE
G
B
E
C


===========================================================================

import java.io.*;
import java.util.*;


//algo
//1. Find how many leap years between 1753 and the given year.
//2. Get the total year difference between the 1753 and the given year.
//3. Add leapCounter to total diffence.
//4. Divide total by 7's
//5. Blah Boom!!! Bahala na, kung anu anu na yan. micropawn217.



public class Dominical2
{





public static void main(String[] star)throws Exception
{


Scanner sc = new Scanner(new BufferedReader (new FileReader("Dominic.in")));


do
{
int yeary;
int yearyHandler=0;
int handsDownDay=0;
int boomYear=1753;
int boomDay=1;
int leapCounter=0;
int extraBoom;
int finalBoom;
int x;



yeary = Integer.parseInt(sc.next());


for(boomYear=1753;boomYear<=yeary;boomYear++)
{
if ((boomYear%4==0) && (boomYear%100!=0) || (boomYear%400==0))
{
leapCounter = leapCounter+1;
}

}



boomYear=1753;
yearyHandler =(yeary-boomYear);
extraBoom = (yearyHandler+leapCounter);

//System.out.println(yearyHandler);
//System.out.println(leapCounter);
//System.out.println(extraBoom);



if ((yeary%4==0) && (yeary%100!=0) || (yeary%400==0))
{

for(x=1;x<=extraBoom;x++)
{
if(handsDownDay>=7)
{
handsDownDay=0;
}
handsDownDay++;
}


//System.out.println("Leap Year");
//System.out.println(handsDownDay);


switch(handsDownDay)
{

case 1:
System.out.println("GF");
break;


case 2:
System.out.println("FE");
break;


case 3:
System.out.println("ED");
break;


case 4:
System.out.println("DC");
break;


case 5:
System.out.println("CB");
break;


case 6:
System.out.println("BA");
break;


case 7:
System.out.println("AG");
break;
}




}

else
{

for(x=0;x<=extraBoom;x++)
{


if(handsDownDay>=7)
{
handsDownDay=0;
}

handsDownDay++;

}


//System.out.println("Common Year");
//System.out.println(handsDownDay);



switch(handsDownDay)
{

case 1:
System.out.println("G");
break;


case 2:
System.out.println("F");
break;


case 3:
System.out.println("E");
break;


case 4:
System.out.println("D");
break;


case 5:
System.out.println("C");
break;


case 6:
System.out.println("B");
break;


case 7:
System.out.println("A");
break;
}
}


yeary=0;
yearyHandler=0;
handsDownDay=0;
boomYear=1753;
boomDay=1;
leapCounter=0;
extraBoom=0;
finalBoom=0;
x=0;

}
while(sc.hasNext());



}




}

Share 

Add a Comment

You need to be a member of Open Source University Meetup to add comments!

Join this social network

3 Comments

° Comment by ° on January 23, 2010 at 2:05am
Hala, nakalimutan ko na ito.
Ron Comment by Ron on April 8, 2009 at 12:38am
Anu yan? San mu nakuha yan? Hehe..
daniel Comment by daniel on March 14, 2009 at 4:08am
nice!

Webinars

OSUM members get exclusive access to a series of webinars on the most innovative open source technologies via the OSUM Webinar Series.

If you missed any of the previous OSUM Webinars, click here to listen to the replays of the previous sessions.

News

NetBeans 6.8 Now Available

NetBeans 6.8 is the first IDE to provide complete support for the new Java EE 6 specification and GlassFish v3 and is now available for download free of charge. Learn all about what's new and cool in NetBeans 6.8 Download NetBeans 6.8

Everything You Ever Wanted To Know About Java EE A free white paper is now available which highlights the features of the new Java EE 6 platform and provides an overview of each of the areas in the platform like EJB, Servlet 3.0, JPA, JSF, and others. The white paper also talks about the evolution of the Java EE standard, the advancements in ease-of-development features that increase developer productivity. Download the white paper. Download NetBeans 6.8, the first IDE to provide full support for the new Java EE 6 specification.

DTrace Toolkit — The “Hidden Little Gem” of OpenSolaris
“With this toolkit there’s probably little need to write a DTrace script from scratch — it’s literally a treasure chest of material that I've only begun to explore,” blogs Brian Leonard on The Observatory.
Read the blog.
Free DTrace Guides Available DTrace, a dynamic tracing facility that is one of the key innovations in OpenSolaris, can be used to examine the behavior of applications and of the operating system itself. Get started with the How To Use DTrace guide or take a deeper dive with the DTrace Quick Start Guide.

Developing MySQL Database Applications With PHP
In this four-part series, Sun engineer, Giri Mandalika provides in-depth tutorials on developing MySQL applications with PHP
Part 1: Using the MySQL Improved Extension, mysqli
Part 2: Using the MySQL Extension, mysql
Part 3: Using the PDO Extension With MySQL Driver, pdo_mysql
Part 4: Using the MySQL Native Driver for PHP, mysqlnd

Coding Conventions for the JavaFX Language

Sun engineer, Tor Norbye documents JavaFX coding conventions including file organization, type definitions, object literals and lots more. Go to Tor's JavaFX Coding Conventions Wiki.

Working With ZFS Snapshots Download the free ZFS Snapshots How-To Guide to learn how to create and use the backup and restore capabilities of ZFS snapshots.

© 2010   Created by Gary Serda

Badge  |  Report an Issue  |  Privacy  |  Terms of Service