交大1043 day of week
来源:互联网 发布:mac flash插件错误 编辑:程序博客网 时间:2024/04/30 19:03
#include<iostream>#include<stdio.h>#include<cstring>using namespace std; int days[13][2]={ 0,0, 31,31, 28,29, 31,31, 30,30, 31,31, 30,30, 31,31, 31,31, 30,30, 31,31, 30,30, 31,31,};char monthName[13][20]={ "", "January", "February", "March", "APril", "May", "June", "July", "August", "September", "October", "November", "December"};char weekName[7][20]={ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; struct Date{ int day; int month; int year; int Isyear()//判断是否是闰年 { if(year%100!=0&&year%4==0||year%400==0) return 1; else return 0; } void nextday(){ int flag = Isyear(); day++; if(day>days[month][flag]) { day=1; month++; if(month>12) { month=1; year++; } } }};int buf[5000][13][32];//设定预处理天数int main(){ Date dat; dat.day=1; dat.month=1; dat.year=0;//设定0.1.1为第一天 int count=0;//天数计算保存 while(dat.year!=5000){ buf[dat.year][dat.month][dat.day]=count;//与0.1.1的天数间隔 dat.nextday(); count++; } int d,m,y; char month[20];//将月份转换为数字 while(scanf("%d%s%d",&d,month,&y)!=EOF) { for(m=1;m<=12;m++) { if(strcmp(month,monthName[m])==0){ break;//找到相应月份的数字 } } int len=buf[y][m][d]-buf[2012][7][16];//找到参照日期,2016.1.4为星期一,且星期一的下标为1,所以要+1 len+=1; int index=(len%7+7)%7;//得到星期的下标,还要保证为非负数,这个方法可以用来处理负数 cout<<weekName[index]<<endl; } return 0;}
0 0
- 交大1043 day of week
- 题目1043:Day of Week
- 题目1043:Day of Week
- 题目1043:Day of Week
- 题目1043:Day of Week
- 题目1043:Day of Week
- 题目1043:Day of Week
- 题目1043:Day of Week
- 题目1043:Day of Week
- 九度1043 Day of Week
- 九度题目1043:Day of Week
- 题目1043:Day of Week 题目7
- 7-题目1043:Day of Week
- 【九度】题目1043:Day of Week
- 九度OJ-1043:Day of Week
- 九度OJ 1043 Day of Week
- 九度[1043]-Day of Week
- Day of Week
- Android Volley完全解析(三),定制自己的Request
- 透传消息和非透传消息
- POJ 2342 Anniversary party (树形dp入门)
- C++类复制构造函数参数为nonconst和const的重载
- android 获取本地图片路径
- 交大1043 day of week
- php生成随机颜色的方法
- [斜率优化小结]
- 奇怪的分式
- Kotlin学习笔记——类和对象
- 极客范:如何使用 Cloud Insight 来监控闭路电视?
- 153.View the Exhibits and examine the structures of the PRODUCTS and SALES tables.
- hdu 1263 水果【二维map+排序】
- DOM7011: 此页上的代码禁用了反向和正向缓存