Skip to content

Instantly share code, notes, and snippets.

@Kaushal28
Created June 13, 2017 14:09
Show Gist options
  • Save Kaushal28/a6ab67de3ec9a1a780120ca67a8cda62 to your computer and use it in GitHub Desktop.
Save Kaushal28/a6ab67de3ec9a1a780120ca67a8cda62 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
class GFG {
public static void main (String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
while(t-->0){
int d = in.nextInt();
int m = in.nextInt();
int y = in.nextInt();
y-=1901;
int leap = y/4;
int nonLeap = y - leap;
int extra = (leap*2 + nonLeap)%7 +1; //+1 for 1 extra till 1900
String days[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
int months[] = {3,1,3,2,3,2,3,3,2,3,2,3};
if((y+1)%4 == 0){ //if leap year then extras in Feb will be 0.
//this %4 checking is enough due to given range.
months[1] = 0;
}
for(int i=0;i<m-1;i++){
extra += months[i];
}
extra += d%7;
if((y+1)>=2000){
System.out.println(days[(extra+1)%7]);
} else{
System.out.println(days[(extra)%7]);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment