course(函数专题)今天星期几
This commit is contained in:
parent
c199712adc
commit
f837682d3a
|
@ -0,0 +1,3 @@
|
|||
# 标题
|
||||
|
||||
* 内容
|
|
@ -0,0 +1,19 @@
|
|||
# 『入门』(函数专题)今天星期几
|
||||
|
||||
[问题描述]
|
||||
|
||||
本题必需使用自定义函数完成
|
||||
|
||||
编一程序实现: 由输入1980年以后的任意一个日期后,计算机能打印出该日期是星期几。系统保证输入的日期肯定是合法,绝不会出现类似-23年13月52日的情况。已知1980年1月1日是星期二。
|
||||
|
||||
[输入格式]
|
||||
年 月 日,日期有3个整数组成,中间用空格隔开。
|
||||
|
||||
[输出格式]
|
||||
一个整数值表示星期几。星期用1 2 3 4 5 6 7表示。(若是星期日就输出7)
|
||||
|
||||
[输入样例]
|
||||
2009 1 2
|
||||
|
||||
[输出样例]
|
||||
5
|
|
@ -0,0 +1,28 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
int main()
|
||||
{
|
||||
int year ,month,day,ans=1,a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
|
||||
cin>>year>>month>>day;
|
||||
ans+=year-1980;
|
||||
if(month>3){
|
||||
year++;
|
||||
}
|
||||
for(int i=1980;i<year;i+=4){
|
||||
if(i%100!=0){
|
||||
ans++;
|
||||
}
|
||||
if(i%400==0){
|
||||
ans++;
|
||||
}
|
||||
}
|
||||
for(int i=1;i<month;i++){
|
||||
ans+=a[i];
|
||||
}
|
||||
ans+=day;
|
||||
ans%=7;
|
||||
if(ans==0){
|
||||
ans=7;
|
||||
}
|
||||
cout<<ans;
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
2009 1 2
|
|
@ -0,0 +1 @@
|
|||
2078 3 24
|
|
@ -0,0 +1 @@
|
|||
2020 4 26
|
|
@ -0,0 +1,18 @@
|
|||
## z:\Chao\src\1651_daytoday\test\in.txt
|
||||
2020/04/24 周五 13:26:59.32
|
||||
5
|
||||
-----------------------------------------------
|
||||
Process exited after 140 ms with return value 0
|
||||
|
||||
## z:\Chao\src\1651_daytoday\test\in2.txt
|
||||
2020/04/24 周五 13:26:59.32
|
||||
4
|
||||
-----------------------------------------------
|
||||
Process exited after 150 ms with return value 0
|
||||
|
||||
## z:\Chao\src\1651_daytoday\test\in3.txt
|
||||
2020/04/24 周五 13:26:59.32
|
||||
7
|
||||
-----------------------------------------------
|
||||
Process exited after 90 ms with return value 0
|
||||
|
Loading…
Reference in New Issue