1024 - int key; int nextkey;...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include<iostream> #include<queue> #include<map> using namespace std; u map<int, int> record; int table[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31}; i int leapyear(int year){ return 1; return 1; return 0; } int getnextmonth(int y, int m, int d){ int key; i if(m == 1){ key = 28; key += leapyear(y); if(d>key){ return -1; } m++; } else if(m == 12){ y++; m = 1; y } else { key = table[m+1]; if(d > key){ return -1; } m ++; } return -1; } key = (y << 16) + (m << 8) + d; return key; } int getnextdate(int y, int m, int d){ int key = table[m]; key += (m==2 & leapyear(y)); if(d < key){ d ++; } else { if(m== 12){ y ++; m = 1; d = 1; y } else { m ++; d= 1; } } return -1; }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
key = (y<<16) + (m <<8) + (d); return key; } int calc(int year, int month, int day){
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int key; int nextkey; map&lt;int,int&gt;::iterator iter; m key = (year&lt;&lt;16) + (month&lt;&lt;8) + (day); iter = record.find(key); if(iter != record.end() ){ return iter-&gt;second; } nextkey = getnextmonth(year,month,day); if(nextkey != -1){ if(0 == calc(nextkey&gt;&gt;16, (nextkey&gt;&gt;8) &amp;0xff, nextkey&amp;0xff)){ record[key] = 1; return 1; } } nextkey = getnextdate(year,month,day); if(nextkey != -1){ if(0 == calc(nextkey&gt;&gt;16, (nextkey&gt;&gt;8) &amp;0xff, nextkey&amp;0xff)){ record[key] = 1; return 1; } } record[key] = 0; return 0; } int main(){ int tstcase; int year,month, day; year = 2001, month = 11, day = 4; year = (year&lt;&lt;16) + (month&lt;&lt;8) + (day); record[year] = 0; cin&gt;&gt;tstcase; while(tstcase --){ cin&gt;&gt;year&gt;&gt;month&gt;&gt;day; if( calc(year,month,day) ){ cout&lt;&lt;&quot;YES\n&quot;; } else { cout&lt;&lt;&quot;NO\n&quot;; } } return 0; }...
View Full Document

Page1 / 2

1024 - int key; int nextkey;...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online