1075 -- 第几天?
2015-08-29 17:06
447 查看
第几天?
Time Limit:1000MS Memory Limit:65536K
Total Submit:99 Accepted:55
Description
给定一个日期,输出这个日期是该年的第几天。
Input
输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,另外,可以向你确保所有的输入数据是合法的。
Output
对于每组输入数据,输出一行,表示该日期是该年的第几天。
Sample Input
Sample Output
Source
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AK1075 {
class Program {
static bool leapyear(int n) {
if ((n % 4 == 0 && n % 100 != 0) || n % 400 == 0)
return true;
return false;
}
static void Main(string[] args) {
string sb;
while ((sb = Console.ReadLine()) != null) {
int x = 0, y = 0;//前面这一大串就是要解决输入问题,真尼玛坑
for (int i = 0; i < sb.Length; i++) {
if (sb[i] == '/' && x == 0)
x = i;
if (sb[i] == '/' && x != 0)
y = i;
}
int year = int.Parse(sb.Substring(0, x));
int month = int.Parse(sb.Substring(x + 1, y - x - 1));
int day = int.Parse(sb.Substring(y + 1, sb.Length - y - 1));
//Console.WriteLine(year + " " + month + " " + day);
int[] a = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };//非闰年
int[] b = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };//闰年
int sum = 0;
if (leapyear(year)) {
for (int i = 0; i < month - 1; i++)
sum += b[i];
sum += day;
} else {
for (int i = 0; i < month - 1; i++)
sum += a[i];
sum += day;
}
Console.WriteLine(sum);
}
}
}
}
Time Limit:1000MS Memory Limit:65536K
Total Submit:99 Accepted:55
Description
给定一个日期,输出这个日期是该年的第几天。
Input
输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,另外,可以向你确保所有的输入数据是合法的。
Output
对于每组输入数据,输出一行,表示该日期是该年的第几天。
Sample Input
1985/1/20 2006/3/12
Sample Output
20 71
Source
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AK1075 {
class Program {
static bool leapyear(int n) {
if ((n % 4 == 0 && n % 100 != 0) || n % 400 == 0)
return true;
return false;
}
static void Main(string[] args) {
string sb;
while ((sb = Console.ReadLine()) != null) {
int x = 0, y = 0;//前面这一大串就是要解决输入问题,真尼玛坑
for (int i = 0; i < sb.Length; i++) {
if (sb[i] == '/' && x == 0)
x = i;
if (sb[i] == '/' && x != 0)
y = i;
}
int year = int.Parse(sb.Substring(0, x));
int month = int.Parse(sb.Substring(x + 1, y - x - 1));
int day = int.Parse(sb.Substring(y + 1, sb.Length - y - 1));
//Console.WriteLine(year + " " + month + " " + day);
int[] a = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };//非闰年
int[] b = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };//闰年
int sum = 0;
if (leapyear(year)) {
for (int i = 0; i < month - 1; i++)
sum += b[i];
sum += day;
} else {
for (int i = 0; i < month - 1; i++)
sum += a[i];
sum += day;
}
Console.WriteLine(sum);
}
}
}
}
相关文章推荐
- 1060 -- 取个标题好难
- 1233 -- 统一资源定位符中的远程服务器地址检测
- akoj-1369 贪吃蛇
- 2016 "Bird Cup" ICPC7th@ahstu--“波导杯”安徽科技学院第七届程序设计大赛
- 【AKOJ】1114-水仙花数
- 【AKOJ】1100-连续和
- 【AKOJ】1184-ASCII码排序(2)
- 【AKOJ】1198-排排队
- 【AKOJ】1313-DNF又爆满啦
- 【AKOJ】1298-B趣味求和
- 【AKOJ】1061-最小公倍数
- 鼠标拖拽事件响应
- RMI * Hessian * Burlap * Httpinvoker * WebService
- 1076 -- Encoding
- DDOS准备
- C/C++内存泄漏及检测
- 原码、补码、反码的概念
- 1074 -- 人见人爱A^B
- 【链表】逆序输出
- CSU 1631 Facility Locations