/** 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
You need to be a member of Open Source University Meetup to add comments!
Join this social network