Esempio n. 1
0
File: 2420.c Progetto: saki45/OJ
int main(){
	char dayOfWeek[7][10] = {"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"};
	int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	int yearst[8010], yr, y, m, d, dw, n;
	yearst[0] = 0;
	for(yr=1; yr<8010; yr++){
		yearst[yr] = yearst[yr-1] + 365 + isLeap(yr+1999);
	}

	scanf("%d", &n);
	while(n >= 0){
		dw = n%7;
		y = bSearch(yearst, 8010, n);
		n -= yearst[y];
		y += 2000;
		for(m=0; ; m++){
			if(m == 1 && n < month[m]+isLeap(y))
				break;
			if(n < month[m])
				break;
			if(m == 1)
				n -= month[m] + isLeap(y);
			else
				n -= month[m];
		}
		d = n+1;
		printf("%d-%02d-%02d %s\n", y, m+1, d, dayOfWeek[dw]);

		scanf("%d", &n);
	}
	return 0;
}
Esempio n. 2
0
/*
int dayOfYear(int day,int month,const int year){
	--month;//0-index
	int month_lengths[]={31,isLeap(year)?29:28,31,30,31,30,31,31,30,31,30,31};
	assert(12==(sizeof(month_lengths)/sizeof(month_lengths[0])));

	if(year<1583
		||month<0||month>=12
		||day<1||day>month_lengths[month])
		return-1;

	for(int i=0;i<month;++i)
		day+=month_lengths[i];
	return day;
}
*/
int dateSplit(int dayOfYear,int year,int*day,int*month){
	if(year<1753
		||dayOfYear<1
		||dayOfYear>(isLeap(year)?366:365))
		return 0;
	if(day==month)return 0;

	int month_lengths[]={31,isLeap(year)?29:28,31,30,31,30,31,31,30,31,30,31};
	*month=1;
	*day=dayOfYear;
	while(*day>month_lengths[*month-1])
		*day-=month_lengths[(*month)++-1];
	return 1;
}
Esempio n. 3
0
int32_t daysFrom1Jan(int32_t year, int32_t month, int32_t day) {
    static const int32_t days[2][12] = {
        { 0,31,59,90,120,151,181,212,243,273,304,334 },
        { 0,31,60,91,121,152,182,213,244,274,305,335 }
    };
    return days[isLeap(year)][month - 1] + day - 1;
}
Esempio n. 4
0
static void changeday ( void )
{
  switch(m_date.month){
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
      increaseday(31);
      break;
    case 4:
    case 6:
    case 9:
    case 11:
      increaseday(30);
      break;
    case 2:
      if(isLeap(m_date.year) == 1){
        increaseday(29);
      }else{
        increaseday(28);
      }
			break;
  }

  
}
Esempio n. 5
0
int getdayofweek (int y, int m, int d) {
	int k = y-1;

	d += 365*k+(k/4)-(k/100)+(k/400)+yeardays[m-1];
    if (isLeap(y) && m>2) d++;
		return d%7;
}
Esempio n. 6
0
    Date Date::advance(const Date& date, Integer n, TimeUnit units) {
        switch (units) {
          case Days:
            return date + n;
          case Weeks:
            return date + 7*n;
          case Months: {
            Day d = date.dayOfMonth();
            Integer m = Integer(date.month())+n;
            Year y = date.year();
            while (m > 12) {
                m -= 12;
                y += 1;
            }
            while (m < 1) {
                m += 12;
                y -= 1;
            }

            QL_ENSURE(y >= 1900 && y <= 2199,
                      "year " << y << " out of bounds. "
                      << "It must be in [1901,2199]");

            Integer length = monthLength(Month(m), isLeap(y));
            if (d > length)
                d = length;

            return Date(d, Month(m), y);
          }
          case Years: {
              Day d = date.dayOfMonth();
              Month m = date.month();
              Year y = date.year()+n;

              QL_ENSURE(y >= 1900 && y <= 2199,
                        "year " << y << " out of bounds. "
                        << "It must be in [1901,2199]");

              if (d == 29 && m == February && !isLeap(y))
                  d = 28;

              return Date(d,m,y);
          }
          default:
            QL_FAIL("undefined time units");
        }
    }
// UEBT - Utilities Epoch-Based Time. Like Unix time but in milliseconds. Epoch is the same.
long long int dateTimeToUEBT(int year, int month, int day, int hour, int minute, int second,
                             int millisecond) {
  long long int time = 0;
  int yr = 1970;
  int mt = 1;
  int days;

  if(year < yr) {
    while(year+1 < yr) {
      days = (isLeap(yr--) ? DAYS_PER_YEAR + 1 : DAYS_PER_YEAR);
      time -= (long long int)days * SECONDS_PER_DAY*1000LL;
    }
    mt = 12;
    while (month < mt) {
      if(mt!=2) days = getMonthDays(mt--);
      else { days = (isLeap(year)? 29 : 28); mt--; }
      time -= (long long int)days * SECONDS_PER_DAY*1000LL;
    }
    days = getMonthDays(month) - day + 1;
    time -= (long long int)days * SECONDS_PER_DAY*1000LL;
    time -= (long long int)(23LL-hour) * SECONDS_PER_HOUR*1000LL;
    time -= (long long int)(59LL-minute) * SECONDS_PER_MINUTE*1000LL;
    time -= (long long int)(59LL-second)*1000LL;
    time -= (long long int)(1000LL-millisecond);
  } else {
    while(yr < year) {
      days = (isLeap(yr++) ? DAYS_PER_YEAR + 1 : DAYS_PER_YEAR);
      time += (long long int)days * SECONDS_PER_DAY*1000LL;
    }
    while (mt < month) {
      if(mt!=2) days = getMonthDays(mt++);
      else { days = (isLeap(year)? 29 : 28); mt++; }
      time += (long long int)days * SECONDS_PER_DAY*1000LL;
    }
    days = day - 1;
    time += (long long int)days * SECONDS_PER_DAY*1000LL;
    time += (long long int)hour * SECONDS_PER_HOUR*1000LL;
    time += (long long int)minute * SECONDS_PER_MINUTE*1000LL;
    time += (long long int)second*1000LL;
    time += (long long int)millisecond;
  }

  return time;
}
Esempio n. 8
0
 Month Date::month() const {
     Day d = dayOfYear(); // dayOfYear is 1 based
     Integer m = d/30 + 1;
     bool leap = isLeap(year());
     while (d <= monthOffset(Month(m),leap))
         --m;
     while (d > monthOffset(Month(m+1),leap))
         ++m;
     return Month(m);
 }
Esempio n. 9
0
int getLast(int year,int month)
{

	if(month==2)
		if(isLeap(year))
			return 29;
		else return 28;
	else if (month==4||month==6||month==9||month==11)
		return 30;
	else return 31;
}
Esempio n. 10
0
int countLeap(int year)
{
    int leap_count = 0;
    int i;
    for(i=1600; i<=year; i++)
    {
        if(isLeap(i)) leap_count++;
    }
    //printf("leaps :%d\n",leap_count);
    return leap_count;
}
Esempio n. 11
0
	//calculates day of the week based on the date
	int dayOfWeek() const
	{
		int val = day;
		val += monthKey[month - 1];
		val += year % 100;
		val += (year % 100) / 4;
		val -= 2 * ((year / 100) % 4);
		if (isLeap(year) && month <= 2)
			val -= 1;
		return (val % 7) + 1;
	}
int validDate(int d,int m,int y)
{
	if (m < 1 || m > 12 || y < 1) //if month or year is invalid
		return 0;
	int maxDays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; //if month and year are valid the initialize max days in a month
	if (isLeap(y)) //checks is a leap year or not
		maxDays[1] ++;  //if leap then increases max days of feb
	if (d < 1 || d > maxDays[m - 1])  //validates the date
		return 0;
	return 1;
}
Esempio n. 13
0
int main(int argc, char* argv[])
{
	int y, m, d, e, i;
	freopen("input.txt", "r", stdin); 
	while(~scanf("%d%d%d", &y, &m, &d)) {
		for (i=e=0;i<m-1;i++) e+=num[i];
		if (isLeap(y)&&m>2)e++;
		printf("%d\n", e+d);
	}
	return 0;
}
Esempio n. 14
0
int day_of_year(int year, int month, int day) {
    char *tab = daytab[isLeap(year)];
    if (month > 12 || month <= 0 || day <= 0 || day > tab[month]) {
        return 0;
    }
    int i;
    for (i = 0; i != month; i++) {
        day += tab[i];
    }
    return day;
}
Esempio n. 15
0
int numberOfDays(struct date d) 
{
	int days;
	const int daysPerMonth[12] = {21, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	if (d.month == 2 && isLeap(d)) { // 二月,并且是闰年
		days = 29;
	} else {
		days = daysPerMonth[d.month - 1];
	}
	return days;
}
Esempio n. 16
0
void main()
{
    //Test Variables
    int year, leap, num, num2, month, day, bitCount;
    month = 2;
    num = 22;
    num2 = 37;
    year = 2004;
    day = daysInMonth(month, year);
    bitCount = countOnes(num);
    leap = isLeap(year);

    //Testing countOnes
    printf("The number of bits in %u is %d\n", num, bitCount);

    //Testing isEven
    if (isEven(num))
    {
        printf("%d is an even number\n", num);
    }
    else
    {
        printf("%d is not an even number\n", num);
    }

    //Testing isOdd
    if (isOdd(num2))
    {
        printf("%d is an odd number\n", num2);
    }
    else
    {
        printf("%d is not an odd number\n", num2);
    }

    //Testing isLeap
    if (leap == 1)
    {
        printf("The year %d is a leap year\n",year);
    }
    else
    {
        printf("The year %d is not a leap year\n",year);
    }

    //Testing daysInMonth
    printf("Febuary has %d days in the year %d\n",day, year);

    //Testing packChars
    printf("Packing %d and %d together forms 0x%x\n", 3, 5, packChars(3,5));

    getchar();
}
Esempio n. 17
0
 J1Date( unsigned int days ) {
     this->_year  = 0;
     this->_month = 0;
     this->_day   = 0;
     // year
     int dd = isLeap(this->_year) ? 366 : 365;
     while (days >= dd) {
         days -= dd;
         this->_year++;
         dd = isLeap(this->_year) ? 366 : 365;
     }
     // month
     dd = _days[isLeap(this->_year) ? 1 : 0][this->_month];
     while (days >= dd) {
         days -= dd;
         this->_month++;
         dd = _days[isLeap(this->_year) ? 1 : 0][this->_month];
     }
     this->_month++;
     this->_day = days + 1;
 }
Esempio n. 18
0
int isValid(int day,int month,int year)
{
	int days[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
	if(isLeap(year))
		days[1]++;
	if(days[month-1]<day||day<1)
		return 0;
	if(year>10000||month>12||month<0)
		return 0;
	return 1;

}
Esempio n. 19
0
void Date::decrementDays(int noOfDays)
{
	int daysInMonths[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
	if(isLeap())
		daysInMonths[2]+=1;
	for(int i=1;i<=noOfDays;i++)
	{
		day--;
		if(day <= 0)
		{
			month--;
			if(month < 1)
			{
				year--;
				if(isLeap())
					daysInMonths[2]+=1;
				month=12;
			}
			day=daysInMonths[month];
		}
	}
}
Esempio n. 20
0
void Date::incrementDays(int noOfDays)
{
	int daysInMonths[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
	if(isLeap())
		daysInMonths[2]+=1;
	for(int i=1;i<=noOfDays;i++)
	{
		day++;
		if(day > daysInMonths[month])
		{
			month++;
			if(month > 12)
			{
				year++;
				if(isLeap())
					daysInMonths[2]+=1;
				month=1;
			}
			day=1;
		}
	}
}
Esempio n. 21
0
int isValid(int dd1, int mm1, int yy1)// returns 1 if date is valid
{
	if (mm1 > 12)
		return 0;
	int max_days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

	if (mm1 == 2 && isLeap(yy1))
		max_days[1]++;

	if (dd1 > max_days[mm1 - 1])
		return 0;
	return 1;
}
Esempio n. 22
0
 void get1stOfMonth(int year, int month, int &firstDay, int &theNumberOfDays) {
     // gets the value of firstDay.
     bool monLt(month<=2);
     int century   = (monLt?year-1:year)/100;
     int lowerYear = (monLt?year-1:year)%100;
     firstDay = lowerYear + lowerYear/4 + century/4 - 2*century + \
                ((26*( (monLt?month+12:month ) + 1))/10);
     firstDay = ((firstDay % 7) + 7) % 7;
     // gets the value of theNumberOfDays.
     theNumberOfDays = MONTHLIST[month];
     if(month == 2 && isLeap(year)) {
         ++theNumberOfDays;
     }
 }
Esempio n. 23
0
    Date::Date(Day d, Month m, Year y) {
        QL_REQUIRE(y > 1900 && y < 2200,
                   "year " << y << " out of bound. It must be in [1901,2199]");
        QL_REQUIRE(Integer(m) > 0 && Integer(m) < 13,
                   "month " << Integer(m)
                   << " outside January-December range [1,12]");

        bool leap = isLeap(y);
        Day len = monthLength(m,leap), offset = monthOffset(m,leap);
        QL_REQUIRE(d <= len && d > 0,
                   "day outside month (" << Integer(m) << ") day-range "
                   << "[1," << len << "]");

        serialNumber_ = d + offset + yearOffset(y);
    }
Esempio n. 24
0
int calOffset(int year,int month, int leap_count)
{
    int offset = 0;
    if(month <= 2)
    {
        if(isLeap(year))
            offset = year - 1601 + leap_count;
        else
            offset = year - 1600 + leap_count;
    }
    else
    {
        offset = year - 1601 + leap_count;

    }
}
Esempio n. 25
0
void month_day(int year, int yearday, int *pmonth, int *pday) {
    *pmonth = *pday = 0;
    char *tab = daytab[isLeap(year)];
    if (yearday <= 0) {
        return;
    }
    int i;
    for (i = 1; i <= 12 && yearday > tab[i]; i++) {
        yearday -= tab[i];
    }
    if (i > 12) {
        return;
    }
    *pmonth = i;
    *pday = yearday;
}
Esempio n. 26
0
//returns the number of days in a given month
//better as a general function, though I originally implemented it inside the class with no parameters, but that was rather limiting
int daysInMonth(int m, int y)
{
	int monthDays = 31;
	switch(m)
	{
	case 2:
		monthDays = (isLeap(y))?29:28;
		break;
	case 4:
	case 6:
	case 9:
	case 11:
		monthDays = 30;
		break;
	}
	return monthDays;
}
Esempio n. 27
0
 // properties
 unsigned int days() const {
     int days = 0;
     
     // before the year
     for (int y = 0; y <= this->_year - 1; y++) {
         days += isLeap(y) ? 366 : 365;
     }
     
     // this year and before th month
     for (int m = 0; m < this->_month-1; m++) {
         days += (int)_days[ this->isLeap(this->_year)? 1 : 0][m];
     }
     
     days += this->_day - 1;
     
     return days;
 }
Esempio n. 28
0
TimeManager& TimeManager::operator+ (TimeManager input) {

	//calculate time
	int hourt = this->hour + input.hour;
	int mint = this->min + input.min;
	double sect = this->sec + input.sec; //TimeManager 부분에서는 double로 선언되어있어서 double로 형변환을 해줌

	//calculate date. Only uses Solar dates
	int solarDayt = this->solarDate.solarDay + input.getSolarDay();
	int solarMontht = this->solarDate.solarMonth + input.getSolarMonth();
	int solarYeart = this->solarDate.solarYear + input.getSolarYear();

	if (sect >= 60) {
	sect -= 60;
	mint++;
	}
	if (mint >= 60) {
	mint -= 60;
	hourt++;
	}
	if (hourt >= 24) {
	hourt -= 24;
	solarDayt++;
	}

	//calculate # of days for given month
	int dayLimit = isDays(this->solarDate.solarMonth);
	if (isLeap(solarYeart)) dayLimit += 1;

	if (solarDayt > dayLimit) {
	solarDayt -= dayLimit;
	solarMontht++;
	}
	if (solarMontht > 12) {
	solarMontht -= 12;
	solarYeart++;
	}

	return TimeManager(solarYeart, solarMontht, solarDayt, hourt, mint, sect);
}
Esempio n. 29
0
void calCalender(int year, int month)
{
    check(year, month);
    int year_start = 1;
    int  offset = 0;
    int leap_count = 0;
    if (year > 1600) offset = calOffset(year, month, countLeap(year));

    //printf("offset: %d\n",offset);
    switch(month)
    {
     case 1:
     case 3:
     case 5:
     case 7:
     case 8:
     case 10:
     case 12:
        output(month, 31, offset);
        break;
     case 2:
        if(isLeap(year))
        {
           output(month, 28, offset);
        }
        else
            output(month, 29, offset);
        break;
     case 4:
     case 6:
     case 9:
     case 11:
        output(month, 30, offset);
        break;
     default :
        printf("Arguments Error!");
    }

}
Esempio n. 30
0
TimeManager& TimeManager::operator+= (TimeManager input) {

	this->hour += input.hour;
	this->min += input.min;
	this->sec += input.sec;
	this->solarDate.solarDay += input.solarDate.solarDay;
	this->solarDate.solarMonth += input.solarDate.solarMonth;
	this->solarDate.solarYear += input.solarDate.solarYear;

	if (this->sec >= 60.0) {
		this->sec -= 60;
		this->min++;
	}
	if (this->min >= 60) {
		this->min -= 60;
		this->hour++;
	}

	if (this->hour >= 24) {
		this->hour -= 24;
		this->solarDate.solarDay++;
	}

	//calculate # of days for given month
	int dayLimit = isDays(this->solarDate.solarMonth);
	if (isLeap(this->solarDate.solarYear)) dayLimit += 1;

	if (this->solarDate.solarDay > dayLimit) {
		this->solarDate.solarDay -= dayLimit;
		this->solarDate.solarMonth++;
	}
	if (this->solarDate.solarMonth > 12) {
		this->solarDate.solarMonth -= 12;
		this->solarDate.solarYear++;
	}

	return *this;
}