当前位置:网站首页>AcWing 3619. 日期 日期处理
AcWing 3619. 日期 日期处理
2022-07-16 06:18:00 【Alkali!】
题目
https://www.acwing.com/problem/content/3622/
今天是 2012 年 4 月 12 日星期四,编写程序,输入今天开始到 12 月 31 日之间的任意日期,输出那一天是星期几。
思路
总的来说是算出 2012 年 4 月 12 日距离给定日期有多少天,然后从 2012 年 4 月 12 日一天一天的加到给定日期。
加的过程中不断进行day=(day+1)%7;操作,结合存储的哈希表,即可算出是星期几:
unordered_map<int,string> M;
void init()
{
M[0]="Monday";
M[1]="Tuesday";
M[2]="Wednesday";
M[3]="Thursday";
M[4]="Friday";
M[5]="Saturday";
M[6]="Sunday";
}
代码
#include<iostream>
#include<unordered_map>
using namespace std;
int m,d,day=2;
unordered_map<int,string> M;
int days[13]={
0,0,0,0,19,31,30,31,31,30,31,30,31};
void init()
{
M[0]="Monday";
M[1]="Tuesday";
M[2]="Wednesday";
M[3]="Thursday";
M[4]="Friday";
M[5]="Saturday";
M[6]="Sunday";
}
int main()
{
init();
scanf("%d%d",&m,&d);
if(m==4)
{
for(int i=12;i<=d;i++)
day=(day+1)%7;
}
else
{
int count=0;
for(int i=4;i<m;i++)
count+=days[i]; //先把整月的天数先算上
count+=d; //算出多出来不满一个月的天数
for(int i=1;i<=count;i++)
day=(day+1)%7;
}
cout<<M[day];
return 0;
}
边栏推荐
- How to choose databases and tables and newsql?
- WWDC22 - In App Purchase 更新总结
- Eureka中读写锁的奇思妙想,太顶了!
- 7-redis architecture design to use scenarios - cache penetration, cache avalanche, cache preheating, cache degradation
- Educational Codeforces Round 131 A - D
- vivado里那些看不懂的约束语句
- Comparison and summary of five deep learning models for time series prediction: from simulated statistical model to unsupervised model that can be pre trained
- 全排序问题
- How does DMS empower database functions?
- Nc16857 [noi1999] birthday cake
猜你喜欢

HMM & MEMM & CRF

7-redis architecture design to use scenarios - cache penetration, cache avalanche, cache preheating, cache degradation

Hal firmware library

小程序毕设作品之微信评选投票小程序毕业设计(7)中期检查报告

Total sequencing problem

Reconstructing the geometric form of weight space with training set

STM32应用开发实践教程:基于 CAN 总线的多机通信应用开发

Will the arrears of Alibaba cloud international ECS be automatically released?

Mitmproxy getting started installation

风控人不能不知的黑产大揭秘
随机推荐
xsslabs通关
Total sequencing problem
求数据流中的中位数问题
Remove the problem of repeated letters (the minimum sequence of different characters)
Design of hydrogen monitoring system based on single chip microcomputer (0490)
风控人不能不知的黑产大揭秘
Will IO always occupy CPU? A good question about concurrent / parallel systems (turn)
Configure maskrcnn environment roast (geforce mx250+win10+tensorflow1.5.0 GPU version)
Stonedb announces open source, why is the integrated real-time HTAP architecture the current best solution
Is there a trap for Huatai Securities to open an account? Is it safe to open an account online?
Internship: analysis of mobile source code
06-GuliMall 基础CRUD功能创建
小程序畢設作品之微信評選投票小程序畢業設計(5)任務書
Go exceed API source code reading (I) -- newfile ()
如何用常数时间插入、删除和获取随机元素
How to choose databases and tables and newsql?
Design of combustible gas smoke system based on single chip microcomputer (0489)
Leetcode (Sword finger offer) - 03 Duplicate numbers in array
The most points on a straight line
Minimum interval problem