日历问题
来源:互联网 发布:店宝宝实物软件 编辑:程序博客网 时间:2024/05/20 02:28
题目
已知2007年10月10日,请求出n天后是几月几号(0<=n<=2000)
输入
多组输入,每组输入为1行,为一个正整数n(1<=n<=2000)
输出
对于每组输入,输出格式为yyyy-mm-dd,输出的值为n天后的日期
样例输入
1
2
样例输出
2007-10-11
2007-10-12
源代码
#include<iostream>
using namespace std;
int b(int);
int main()
{
int n,i,j;
int year,month,day,leap[2]={365,366};
int a[2][12]=
{31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31};
while(cin>>n)
{
n=n+282;
for(year=2007;n>=leap[b(year)];year++)
n-=leap[b(year)];
for(month=0;n>=a[b(year)][month];month++)
n-=a[b(year)][month];
day=n+1;
cout<<year<<"-";
if((month+1)<10)
cout<<"0"<<month+1;
else
cout<<month+1;
cout<<"-";
if(day<10)
cout<<"0"<<day<<endl;
else
cout<<day<<endl;
}
return 0;
}
int b(int x)
{
if(x%4==0&&x%100!=0||x%400==0)
return 1;
else
return 0;
}
- 日历问题
- 日历问题
- 日历问题
- 日历问题
- 日历问题
- 日历问题
- 问题 G: 日历问题
- 日历控件问题
- 日历控件问题求教!
- POJ 2964 日历问题
- struts日历问题 ,总结
- 5.3日历问题
- poj2964 日历问题
- POJ2080日历问题
- 5.3poj2964日历问题
- POJ 2964:日历问题
- android中日历问题
- POJ2964日历问题
- OracleService服务不见了|OracleServiceXE服务没有了
- method 与 function的区别
- 【推荐】.NET使用NPOI组件将数据导出Excel
- 设计模式之单例模式
- JAVA Timer 分析
- 日历问题
- [leetcode] Binary Tree Preorder Traversal 非递归先序遍历
- 小波变换 通俗解读(2)
- JAVA的ThreadLocal
- PHP str_replace() 函数
- git教程
- 算法课第7周作业——背包问题
- 鸡兔同笼
- 第1次实验——NPC问题(回溯算法、聚类分析).....