您的位置:首页 > 其它

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
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);
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  akoj