我出个题目。
一块带日历的机械表,在多少天后日历又能正确。
比如,现在是2012年1月1日,机械表的日历也是1日,
到2012年3月1日的时候,机械表的日历是30日,现在出现了偏差。
问不调的情况下,到哪天日历又能一样。
这个题目不难,关键是集思广益,看看有多少思路。
注:第一个正确答案50分。
[解决办法]
#include <afxdisp.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, TCHAR* argv[]) {
COleDateTime t;
COleDateTimeSpan ts;
CString s,fmt;
int nYear;
int nMonth;
int nDay;
int nHour;
int nMin;
int nSec;
int lDays;
int nHours;
int nMins;
int nSecs;
int i,N;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) {
printf("Fatal Error: MFC initialization failed\n");
return 1;
}
if (argc<13) {
printf("Usage:%s sYYYY sMM sDD shh smm sss pDD phh pmm pss n {SQL
[解决办法]
YYYY
[解决办法]
YY}\n",argv[0]);
return 2;
}
if (stricmp(argv[12],"SQL")==0) fmt="%Y-%m-%d %H:%M:%S";
else if (stricmp(argv[12],"YYYY")==0) fmt="%Y%m%d %H%M%S";
else if (stricmp(argv[12],"YY")==0) fmt="%y%m%d %H%M%S";
else {
printf("Usage:%s sYYYY sMM sDD shh smm sss pDD phh pmm pss n {SQL
[解决办法]
YYYY
------解决方案--------------------
YY}\n",argv[0]);
return 3;
}
nYear =atoi(argv[ 1]);
nMonth=atoi(argv[ 2]);
nDay =atoi(argv[ 3]);
nHour =atoi(argv[ 4]);
nMin =atoi(argv[ 5]);
nSec =atoi(argv[ 6]);
lDays =atoi(argv[ 7]);
nHours=atoi(argv[ 8]);
nMins =atoi(argv[ 9]);
nSecs =atoi(argv[10]);
N =atoi(argv[11]);
if (N<=0) {
printf("Usage:%s sYYYY sMM sDD shh smm sss pDD phh pmm pss n {SQL
[解决办法]
YYYY
[解决办法]
YY}\n",argv[0]);
return 4;
}
t=COleDateTime( nYear, nMonth, nDay, nHour, nMin, nSec);
ts=COleDateTimeSpan( lDays, nHours, nMins, nSecs );
for (i=1;i<=N;i++) {
s=t.Format(fmt);
printf("%08d %s\n",i,s);
t=t+ts;
}
return 0;
}
#include <stdio.h>
void main()
{
int m,n;
int total;
int a[5]={60,121,182,274,335};
int b[5]={3,5,7,10,12};
m=n=0;
while(m<1000)
{
for (int i=0;i<5;i++)
{
total=366*((m+3)/4)+365*(m-(m+3)/4)+a[i]-1+(m%4==0?1:0);
if(total%31==0)
{
printf("%04d-%02d-1",2012+m,b[i]);
m=100000;
break;
}
}
m++;
}
}