NEUQ 1269: 第几天
来源:互联网 发布:如何关闭windows更新 编辑:程序博客网 时间:2024/06/02 11:47
1269: 第几天
题目描述
给定一个日期,输出这个日期是该年的第几天。
输入
输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,另外,可以向你确保所有的输入数据是合法的。
输出
对于每组输入数据,输出一行,表示该日期是该年的第几天。
样例输入
1985/1/202006/3/12
样例输出
2071
提示
来源
吉首大学软件学院
分析:
水题,简单的运算问题。
LANGUAGE:C++
CODE:
#include <iostream>using namespace std;bool judge(int n){ if(n%4==0||(n%100!=0&&n%400==0)) return true; return false;}int solve(int n){ int s=0; switch(n) { case 12: s+=30; case 11: s+=31; case 10: s+=30; case 9: s+=31; case 8: s+=31; case 7: s+=30; case 6: s+=31; case 5: s+=30; case 4: s+=31; case 3: s+=29; case 2: s+=31; } return s;}int main(){ int a,b,c; while(scanf("%d/%d/%d",&a,&b,&c)!=EOF) { if(judge(a)) cout<<solve(b)+c<<endl; else if(b>2) cout<<solve(b)+c-1<<endl; else cout<<solve(b)+c<<endl; }}
用数组+for循环可以简化程序。
CODE:
#include <iostream>#include <cstdio>using namespace std;int main(){ int n[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int a,b,c; while(scanf("%d/%d/%d",&a,&b,&c)!=EOF) { if((a%4==0) ||(a%400==0&&a%100!=0)) n[2]=29; int tian=0; for(int i=1;i<b;i++) tian=tian+n[i]; tian=tian+c; cout<<tian<<endl; } return 0;}
0 0
- NEUQ 1269: 第几天
- 第几天
- 【第几天?】
- 第几天?
- 第几天
- 第几天?
- 第几天
- 第几天
- 第几天?
- 第几天
- 第几天
- 第几天?
- 第几天
- 第几天?
- 第几天
- 第几天
- 第几天?
- 第几天?
- [C#] Parallel.For的线程数
- HTML5 Web Storage代码
- Android Eclipse工程开发中的常见调试问题(一)
- poj 2411
- 获取ios相册gif图片 原数据
- NEUQ 1269: 第几天
- Mac OS X 搭建erlang开发环境
- *LeetCode-Binary Tree Postorder Traversal
- PAT(B)1014. 福尔摩斯的约会 (20)
- selenium+python---更轻松的sleep()
- UVA 1366-Martian Minging(DP)
- Regular Expression Matching
- 小姑娘的直行机器人-升级版
- Linux环境变量配置文件修改