NYOJ219 a problem about data
来源:互联网 发布:mac rebel 编辑:程序博客网 时间:2024/04/26 04:35
给出日期计算周几。
公式留作备用。
#include<iostream>#include<cstring>#include<cstdio>#include<cmath>#include<algorithm>#include<cstdlib>using namespace std;int Hash[7]= {5,6,0,1,2,3,4};int run[13]= {0,31,29,31,30,31,30,31,31,30,31,30,31};int pin[13]= {0,31,28,31,30,31,30,31,31,30,31,30,31};int yy[10000];//暴力方法,闰年预处理void init() { yy[1600]=1; for(int i=1601; i<=9600; i++) { if(i%400==0||(i%100&&i%4==0)) { yy[i]=yy[i-1]+1; } else { yy[i]=yy[i-1]; } }}int main() { int y,m,d; init(); while(~scanf("%d%d%d",&y,&m,&d)) { int ans=(y-1600)*365; ans+=yy[y-1]; if(y%400==0||(y%100!=0&&y%4==0)) { for(int i=0; i<m; i++) { ans+=run[i]; } ans+=d; } else { for(int i=0; i<m; i++) { ans+=pin[i]; } ans+=d; } printf("%d\n",Hash[ans%7]); } return 0;}//公式<span style="display: none; width: 0px; height: 0px;" id="transmark"></span>int main(){ int y, m, d, w; while(scanf("%d%d%d", &y, &m, &d) == 3){ if(m < 3) m += 12, --y; w = ( d + 2*m + 3*(m+1)/5 + y + y/4 - y/100 + y/400 + 1) % 7; printf("%d\n", w); } return 0;}
0 0
- NYOJ219 a problem about data
- NYOJ219-An problem about date
- NYOJ219 An problem about date 【数学】
- A problem about printf
- A problem about Autoinvoice
- A problem about date
- A Problem about Polyline
- nyoj219
- NYOJ 216 An problem about data
- 南工219 A Problem About Date
- cf 320# A Problem about Polyline (二分)
- PKU 1020 A Problem about Tree LCA
- cf#320 Div.2 Problem C A Problem about Polyline
- cf#320 Div.2 Problem C A Problem about Polyline
- Codeforces Round #320 (Div. 1) A. A Problem about Polyline
- About data
- solved a problem about undefined / unresolved reference in c
- My first blog!! About a problem in SQL 2005 configuration...
- SqlServer索引的原理与应用
- 在 keil MDK_V5中加入arm7,arm9等一些芯片型号
- Vijos P1412 多人背包
- -webkit-line-clamp 多行文字溢出...
- Android21--Android之Android中的Fragment
- NYOJ219 a problem about data
- HDU 4463 Outlets
- 打印俄文
- FileReader:读取图片文件并显示
- 什么事ORM框架
- spring in action第1章,第2章
- 24. Swap Nodes in Pairs
- 函数开始处的MOV EDI, EDI的作用
- 内核启动过程