602 - What Day Is It?
Moderator: Board moderators
602WA
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
int leepyear(int year){
if(year%4!=0)
return 0;
else if(year%100!=0)
return 1;
else if(year%400!=0)
return 0;
else
return 1;
}
int Zeller(int Y,int M,int D){
int y=Y-1;
int leepx,x,xx,xxx=0;
if(M>2||(M==2&&D==29))
{
if(Y%4!=0)
leepx=0 ;
else if(Y%100!=0)
leepx=1 ;
else if(Y%400!=0)
leepx=0 ;
else
leepx=1;}
if(M<=7)
xx=30*(M-1)+M/2+D;
if(M>=8)
xx=214+30*(M-8)+(M-7)/2+D;
if(M<=2)
x=0;
if(M>=3)
x=(leepx-2);
if((Y<1752)||(Y==1752&&M<9)||(Y==1752&&M==9&&D<14))
xxx=4;
return (((y+y/4-y/100+y/400)%7+xx%7-1+x+1+xxx)%7) ;
}
int main(void){
int i=-1,j;
int Y[100],M[100],D[100];
int monthend[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
char month[12][12]={"January","February","March","April","May","June","July","August","September","October","November","December"};
char week[7][12]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saterday"};
#ifndef ONLINE_JUDGE
close (0); open ("myprog.in", O_RDONLY);
close (1); open ("myprog.out1", O_WRONLY | O_CREAT, 0600);
#endif
while (scanf("%d%d%d",&M,&D,&Y)!=EOF){
do{
i++;
scanf("%d %d %d",&M,&D,&Y);
}while(Y!=0 || M!=0 || D!=0);
for(j=0;j<i;j++){
if(((Y[j]==1752&&M[j]==9)&&(D[j]==3||D[j]==4||D[j]==5||D[j]==6||D[j]==7||D[j]==8||D[j]==9||D[j]==10||D[j]==11||D[j]==12||D[j]==13))||M[j]<1 || M[j]>12 || D[j]<1 || (M[j]!=2 && D[j]>monthend[M[j]]) || (M[j]==2 && D[j]>(28+leepyear(Y[j]))) )
printf("%d/%d/%d is an invalid date.\n",M[j],D[j],Y[j]);
else
printf("%s %d, %d is a %s\n",month[M[j]-1],D[j],Y[j],week[Zeller(Y[j],M[j],D[j])]);
}
}
return 0;
}
why I got "WA"?
please help me.
>"<
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
int leepyear(int year){
if(year%4!=0)
return 0;
else if(year%100!=0)
return 1;
else if(year%400!=0)
return 0;
else
return 1;
}
int Zeller(int Y,int M,int D){
int y=Y-1;
int leepx,x,xx,xxx=0;
if(M>2||(M==2&&D==29))
{
if(Y%4!=0)
leepx=0 ;
else if(Y%100!=0)
leepx=1 ;
else if(Y%400!=0)
leepx=0 ;
else
leepx=1;}
if(M<=7)
xx=30*(M-1)+M/2+D;
if(M>=8)
xx=214+30*(M-8)+(M-7)/2+D;
if(M<=2)
x=0;
if(M>=3)
x=(leepx-2);
if((Y<1752)||(Y==1752&&M<9)||(Y==1752&&M==9&&D<14))
xxx=4;
return (((y+y/4-y/100+y/400)%7+xx%7-1+x+1+xxx)%7) ;
}
int main(void){
int i=-1,j;
int Y[100],M[100],D[100];
int monthend[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
char month[12][12]={"January","February","March","April","May","June","July","August","September","October","November","December"};
char week[7][12]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saterday"};
#ifndef ONLINE_JUDGE
close (0); open ("myprog.in", O_RDONLY);
close (1); open ("myprog.out1", O_WRONLY | O_CREAT, 0600);
#endif
while (scanf("%d%d%d",&M,&D,&Y)!=EOF){
do{
i++;
scanf("%d %d %d",&M,&D,&Y);
}while(Y!=0 || M!=0 || D!=0);
for(j=0;j<i;j++){
if(((Y[j]==1752&&M[j]==9)&&(D[j]==3||D[j]==4||D[j]==5||D[j]==6||D[j]==7||D[j]==8||D[j]==9||D[j]==10||D[j]==11||D[j]==12||D[j]==13))||M[j]<1 || M[j]>12 || D[j]<1 || (M[j]!=2 && D[j]>monthend[M[j]]) || (M[j]==2 && D[j]>(28+leepyear(Y[j]))) )
printf("%d/%d/%d is an invalid date.\n",M[j],D[j],Y[j]);
else
printf("%s %d, %d is a %s\n",month[M[j]-1],D[j],Y[j],week[Zeller(Y[j],M[j],D[j])]);
}
}
return 0;
}
why I got "WA"?
please help me.
>"<
i tried every single test case given here, somehow all testcase worked, though i am still getting WA!
for the last test case
thanks in advance!
for the last test case
i got this outputsinput
9 2 1752
9 14 1752
9 15 1752
9 30 1752
10 1 1752
12 31 1752
1 1 1753
0 0 0
Okay, to define i used macros, and my code is the following, i wont bother you to debug my code, (you know its tiring, that right now, everyone is too busy to help), if you got ac, plz plz find me some testcase for what my code do not work....
output
September 2, 1752 is a Wednesday
September 14, 1752 is a Thursday
September 15, 1752 is a Friday
September 30, 1752 is a Saturday
October 1, 1752 is a Sunday
December 31, 1752 is a Sunday
January 1, 1753 is a Monday
Code: Select all
/*
* 602 what day is it?
* submission 1 WA 2 WA 3 WA 4 WA 5 RF 6 WA 7 WA 8 WA
* coded at 11:31 pm , 23th dec 2005
*
*/
#include <stdio.h>
#define jleap(year) ((year)%4==0)
#define gleap(year) ((year%400==0) || ((year%4==0) && (year%100!=0)))
//jleap counting
int countj(int year) {
long i,count=0;
if(!jleap(year))
count=(int)(year/4)+1;
else count=(int)(year/4);
//for(i=0;i<year;i+=4)
// if(jleap(year))count++;
return count;
}
//gleap counting
int countg(int year) {
long i,count=0,start;
for(start=1753;;start++)
if(gleap(start)) break;
for(i=start;i<year;i+=4)
if(gleap(i))count++;
return count;
}
//return days of a month
int dayzof(int mm,int year,int value) {
int MAX=31;
switch (mm) {
case 4:
case 6:
case 9:
case 11:
MAX = 30;
break;
case 2:
MAX = 28;
if(value==1) {
if jleap(year) MAX=29;
}else if gleap(year) MAX=29;
break;
}
return MAX;
}
//return date
int return_date(int mm,int dd,int yy,int value) {
//this part all it will do is to return date;
//it will calculate (total_year+leap_year+days_of_this_year) mod 7
long ans;
long leapy,days=0;
int begining;
int i;
leapy= (value==1) ? countj(yy): countg(yy);
for(i=1;i<mm;i++)
days+=dayzof(i,yy,value);
days+=dd;
ans= leapy+days+yy;
ans= (value==1) ? ans : ans-1752;
begining= (value==1) ? 4 : 0;
ans+=begining;
ans=ans%7;
return (int)ans;
}
//checking validity
int chkvalid(int mm,int dd,int year,int value) {
int MAX;
if(mm>12 || mm<1) return 0;
MAX=dayzof(mm,year,value);
if(dd>MAX) return 0;
return 1;
}
//main function
int main() {
char day[7][10]={"Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"};
char month[12][15]={"January","February","March","April","May","June","July","August","September","October","November","December"};
int dd,mm,yy;
int value;
char ans;
//freopen("h:\\test.in","r", stdin);
//freopen("h:\\output.out","w", stdout);
while(scanf("%d%d%d",&mm,&dd,&yy)==3) {
if(!mm && !dd && !yy) break;
value = (yy<=1752) ? 1:2;
//this block is just for year 1752, the most sensitive year
if(yy==1752) {
if(mm==9) {
if(dd>=3 && dd<=13) {
printf("%d/%d/%d is an invalid date.\n",mm,dd,yy);
continue;
}
}
if(mm>9 || (mm==9 && dd>=14)) {
value=0;
for(int i=9;i<mm;i++)
value+=dayzof(i,yy,2);
value+=dd-12;
value+=3; // here 3 is just a constant to justify the begining;
value%=7;
printf("%s %d, %d is a %s\n",month[mm-1],dd,yy, day[value]);
continue;
}
}
if(!chkvalid(mm,dd,yy,value)) {
printf("%d/%d/%d is an invalid date.\n",mm,dd,yy);
continue;
}
ans=return_date(mm,dd,yy,value);
printf("%s %d, %d is a %s\n",month[mm-1],dd,yy, day[ans]);
}
return 0;
}
fahim
#include <smile.h>
#include <smile.h>
-
- Learning poster
- Posts: 83
- Joined: Wed Feb 01, 2006 12:59 pm
- Location: (Fci-cu) Egypt
- Contact:
602 please some test cases
I got many wa.
Please can any one give me tricky test cases
Please can any one give me tricky test cases
Sleep enough after death, it is the time to work.
Mostafa Saad
Mostafa Saad
-
- New poster
- Posts: 13
- Joined: Fri Nov 03, 2006 2:53 pm
- Location: bangladesh
- Contact:
602 WA
i have tried but got wa.
if the year is 1752 & month is september &date is within 3-13 what is the output. invalid date?
How could be the integer limit.
can any one help me giving some tricky tests.
if the year is 1752 & month is september &date is within 3-13 what is the output. invalid date?
How could be the integer limit.
can any one help me giving some tricky tests.

Well, I'll post my code, too - no idea what's wrong. I thought that I could use the built-in library, had to learn some weird crap about it, too (September 14th, 1752 is a Date(-148,8,14) - go figure). That thing that compares month/day to the original - GregorianCalendar doesn't mind February 30th, it just turns it into March 2nd (or 1st).
Code: Select all
import java.io.IOException;
import java.util.Date;
import java.util.GregorianCalendar;
class Main {
private int inputIndex;
private int inputSize;
private byte[] input;
private void work() {
String[] months = { "January", "February", "March", "April", "May",
"June", "July", "August", "September", "October", "November",
"December" };
String[] days = { "Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday" };
readAll(1 << 22);
while (true) {
int mm = nextInt();
int dd = nextInt();
int yy = nextInt();
if ((mm | yy | dd) == 0)
break;
if (yy < 1 || mm < 1 || mm > 12 || dd < 1 || dd > 31) {
System.out.println(mm + "/" + dd + "/" + yy
+ " is an invalid date.");
continue;
}
if (yy == 1752 && mm == 9 && (3 <= dd && dd <= 13)) {
System.out.println(mm + "/" + dd + "/" + yy
+ " is an invalid date.");
continue;
}
GregorianCalendar gc = new GregorianCalendar();
gc.setGregorianChange(new Date(-148, 8, 14)); // weird, innit?
gc.set(yy, mm - 1, dd);
if (mm - 1 != gc.get(GregorianCalendar.MONTH)
|| dd != gc.get(GregorianCalendar.DAY_OF_MONTH)) {
System.out.println(mm + "/" + dd + "/" + yy
+ " is an invalid date.");
continue;
}
System.out.print(months[gc.get(GregorianCalendar.MONTH)] + " ");
System.out.print(dd + ", ");
System.out.print(yy + " is a ");
System.out.println(days[gc.get(GregorianCalendar.DAY_OF_WEEK) - 1]);
}
}
private void readAll(int bufSize) {
input = new byte[bufSize];
int start = 0;
inputSize = 0;
while (true) {
try {
int read = System.in.read(input, start, 2048);
inputSize += read;
if (read < 2048)
break;
start += 2048;
} catch (IOException e) {
}
}
inputIndex = 0;
}
private int nextInt() {
while (input[inputIndex] < '-') {
inputIndex++;
if (inputIndex >= inputSize)
return Integer.MIN_VALUE;
}
int k = 0;
int sign = 1;
if (input[inputIndex] == '-') {
inputIndex++;
sign = -1;
} else
k = input[inputIndex++] - 48;
while (input[inputIndex] >= '0' && input[inputIndex] <= '9') {
k *= 10;
k += (input[inputIndex++] - 48);
}
return k * sign;
}
public static void main(String args[]) {
Main myWork = new Main();
myWork.work();
}
}
be careful ,the name of moths, and weekdays , if you write them wrong......
////////////////////////////
char * monthName[]={"January","February","March","April",
"May","June","July","August",
"September","October","November","December"
};
char * week[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
////////////////////////////
char * monthName[]={"January","February","March","April",
"May","June","July","August",
"September","October","November","December"
};
char * week[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
-
- New poster
- Posts: 19
- Joined: Fri Sep 05, 2008 6:39 pm
- Location: bangladesh
- Contact:
why WA???????help me
Code: Select all
#include<stdio.h>
int main(){
int i,mon[]={31,28,31,30,31,30,31,31,30,31,30,31},sum,track;
char month[][15]={"January","February","March","April","May","June","July","August","September","October","November","December"};
char date[][15]={"Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"};
int d,m,y;
/* freopen("friday.in","r",stdin);
freopen("friday.out","w",stdout);*/
while(scanf("%d %d %d",&m,&d,&y)&&!(!m&&!d&&!y)){
if(d<=0||m<=0||y<0){
printf("%d/%d/%d is an invalid date.\n",m,d,y);
continue;
}
sum=0;
for(i=0;i<y;i++){
if(i%4==0){
if(i%100==0&&i>1752){
if(i%400==0)
sum=(sum%7+(366)%7)%7;
else
sum=(sum%7+(365)%7)%7;
}
else if(i==1752)sum=(sum%7+(366-11)%7)%7;
else
sum=(sum%7+(366)%7)%7;
}
else sum=(sum%7+(365)%7)%7;
}
for(i=0;i<m-1;i++){
if(i==1&&y%4==0){
if(y%100==0){
if(y%400==0)
sum=(sum%7+(29)%7)%7;
else
sum=(sum%7+(28)%7)%7;
}
else
sum=(sum%7+(29)%7)%7;
}
else if(y==1752&&i==8)sum=(sum%7+(mon[i]-11)%7)%7;
else sum=(sum%7+(mon[i])%7)%7;
}
track=1;
if(m>12)track=0;
else if(d>mon[m-1]&&m!=2)track=0;
else if(d>mon[m-1]){
if(d==29){
if(y%4==0){
if(y%100==0){
if(y%400==0)
sum=(sum%7+d%7)%7;
else track=0;
}
else sum=(sum%7+d%7)%7;
}
else track=0;
}
else track=0;
}
else if(y==1752&&m==9){
if(d>13)
sum= (sum%7 + (d-11)%7)%7;
else if(d>2&&d<14)track=0;
else
sum=(sum%7 + d%7)%7;
}
else sum=(sum%7 + d%7)%7;
sum+=4;
if(sum>6)sum-=7;
if(track) printf("%s %d, %d is a %s\n",month[m-1],d,y,date[sum]);
else printf("%d/%d/%d is an invalid date.\n",m,d,y);
}
return 0;
}
but i m getting WA






-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 602 - What Day Is It?
Darko, I also couldn't get AC using JAVA's GregorianCalendar. I got AC using C and checked that against my JAVA code for all inputs of year 1 to 3000, month 1 to 12, and day 1 to 31 and found no differences. My C code uses scanf, maybe there's some odd input formatting. When I compile using javac, I get a warning that Date is deprecated, that might be an issue.
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 1
- Joined: Sun Apr 14, 2013 9:31 pm
uva problem 602
I don't understand why my code is getting wrong answer while submitting.Plz someone tell me for which input it is not working
Code: Select all
#include<iostream>
#include<fstream>
using namespace std;
int LeapYear(int);
bool isValid(int,int,int);
int days_in_month[12]={31,28,31,30,31,30,31,31,30,31,30,31};
char name_of_month[12][10]={"January", "February", "March", "April", "May", "June","July", "August", "September", "October", "November", "December"};
char name_of_day[7][10]={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday","Saturday"};
char name_of_day2[7][10]={"Friday","Thursday","Wednesday" ,"Tuesday", "Monday","Sunday" , "Saturday"};
int main()
{
int month,day,year;
//freopen("602.txt","r",stdin);
while(cin >> month>>day>>year)
{
if(month==0 && day==0 && year==0) break;
if(!isValid(month,day,year))
{
cout << month <<'/'<<day<<'/'<<year <<" is an invalid date.\n";
continue;
}
unsigned int count=0;
if(year>=2000)
{
for(int yr=0;yr<year;yr++) count=(count+365+LeapYear(yr))%7;
for(int m=0;m<month-1;m++)
{
count=(count+days_in_month[m])%7;
if(m==1 && LeapYear(year)) count=(count+1)%7;
}
count=(count+day+6)%7;
cout << name_of_month[month-1] <<" "<<day<<", "<<year<<" is a "<<name_of_day[count] << endl;
}
else
{
for(int yr=year+1;yr<2000;yr++) count=(count+365+LeapYear(yr))%7;
for(int m=month;m<12;m++)
{
count=(count+days_in_month[m])%7;
if(m==1 && LeapYear(year)) count=(count+1)%7;
}
count=(count+days_in_month[month-1]-day)%7;
if(LeapYear(year) && month==2) count=(count+1)%7;
if(year==1752 && month <=9 && day <14) count=(count+3)%7;
else if(year < 1752) count=(count+3)%7;
cout << name_of_month[month-1] <<" "<<day<<", "<<year<<" is a "<<name_of_day2[count] << endl;
}
}
return 0;
}
bool isValid(int month,int day,int year)
{
if (year == 1752 && month == 9 && day > 2 && day <14 ) return false;
if(month > 12 || month <1 || day < 1) return false;
if(month!=2 && day >days_in_month[month-1]) return false;
if( month==2 && day > (days_in_month[month-1]+LeapYear(year))) return false;
return true;
}
int LeapYear(int yr)
{
if(yr<=1752)
{
if(yr%4==0) return 1;
else return 0;
}
else if(yr%400==0) return 1;
else if(yr%100==0) return 0;
else if(yr%4==0) return 1;
else return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: uva problem 602
February 29, 1952 is a Friday
Check input and AC output for thousands of problems on uDebug!