An problem about date

An problem about date

时间限制:2000 ms  |  内存限制:65535 KB

难度:2

描述

acm的iphxer经常忘记某天是星期几,但是他记那天的具体日期,他希望你能写个程序帮帮他。

输入
每行有三个整数 year,month,day,日期在1600年1月1日到9600年1月1日之间;
输出
输出对应的星期,用一个整数表示;(星期一到星期六用1-6表示,星期日用0表示)
样例输入
2011 3 6
1949 10 1
2011 4 1
1945 8 15
样例输出
0
6
5
3

我的代码:

#include <cstdio>
int main()
{
	int w,y,m,d;
	while (~scanf("%d %d %d",&y,&m,&d))
	{
		if(m==1||m==2)
		{
			m+=12;
			y--;
		}
		w=(d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400 ) % 7;
		w = w >=0 ? (w+1)%7 : (w+8)%7 ;
		printf("%d\n",w);
	}
	return 0;
}

标程:


#include<cstdio>
int main()
{
	int y,m,d;
	while(~scanf("%d%d%d",&y,&m,&d))
	{
		if(m<3) m+=12,--y;
		printf("%d\n",(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400+1)%7); //蔡勒公式的变种
	}
}                      
时间: 2024-08-02 12:25:56

An problem about date的相关文章

NYOJ-219 An problem about date

An problem about date 时间限制:2000 ms  |  内存限制:65535 KB 难度:2 描述 acm的iphxer经常忘记某天是星期几,但是他记那天的具体日期,他希望你能写个程序帮帮他. 输入 每行有三个整数 year,month,day,日期在1600年1月1日到9600年1月1日之间; 输出 输出对应的星期,用一个整数表示;(星期一到星期六用1-6表示,星期日用0表示) 样例输入 2011 3 6 1949 10 1 2011 4 1 1945 8 15 样例输出

NYOJ219 An problem about date 【数学】

An problem about date 时间限制:2000 ms  |  内存限制:65535 KB 难度:2 描述 acm的iphxer经常忘记某天是星期几,但是他记那天的具体日期,他希望你能写个程序帮帮他. 输入 每行有三个整数 year,month,day,日期在1600年1月1日到9600年1月1日之间; 输出 输出对应的星期,用一个整数表示;(星期一到星期六用1-6表示,星期日用0表示) 样例输入 2011 3 6 1949 10 1 2011 4 1 1945 8 15 样例输出

南阳219----An problem about date

1 /* 2 1600年一月一日为星期6,所以算出ymd与1600-1-1差多少天对7取余即可 3 */ 4 #include<stdio.h> 5 int a[10000]={0}; 6 int main() 7 { 8 int i,y,m,d,t = 0,ans; 9 for(i=1600; i<9601; i+=4) 10 { 11 if(i%100 != 0 || i%400==0) 12 ++t; 13 a[i-1599] = a[i-1598] = a[i-1597] = a

An problem about date 根据年月日计算 星期几

/W = (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400) mod 7(1.2月需要看作上一年的13.14月) #include<stdio.h> #include<string.h> #include<math.h> #include<iostream> #include<algorithm> #include<queue> #include<vector> #include<set>

nyoj 219 An problem about date 日期计算 附加最优代码(基姆拉尔森公式)

第一次直接计算的   超时了.后来把天数存贮在数组中 也算过了 不知道这题为什么分类在动态规划里面 #include <stdio.h> int main() { int a[13]={0,31,29,31,30,31,30,31,31,30,31,30,31},year,mon,day; long long b[9605]={0},sum=0; for(int i=1600;i<9600;i++) { if(i%4==0&&i%100||i%400==0) sum+=3

oracle 报错 :ORA-04052、 ORA-00604、 ORA-03106、 ORA-02063

最近发现一个很奇怪的问题: 创建了一个DB_LINK连接另一个Oracle数据库. select * from [email protected]; 单句执行没问题,但是把这句SQL写到存储过程内: create or replace procedure prc_testisbegininsert into testselect * from [email protected];commit; end; 就发生如下错误,存储过程编译不通过: 报错如下:PACKAGE BODY SKSKJ.PKG

SPOJ GSS2 Can you answer these queries II

Time Limit: 1000MS   Memory Limit: 1572864KB   64bit IO Format: %lld & %llu Description Being a completist and a simplist, kid Yang Zhe cannot solve but get Wrong Answer from most of the OI problems. And he refuse to write two program of same kind at

The Alphabet Sticker

题目大意:给你一串字符串,其中有一部分未知,用'?'表示. 现在定义一种合法的Sticker,比如"aabcc","ccccab".即所有相同的字母要在一起才是合法的.现在请问对于给定的字符串,有多少种合法的结果. 比如:"aa??bb"合法的字符串有三种. 分别是"aaaabb" "aaabbb" "aabbbb". '?'表示的字符只能从已经给出的字符中选,所以"aaccb

Codeforces#200 div.2

Description Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two mag