1075 -- 第几天?

来源:互联网 发布:矩阵关联分析法 编辑:程序博客网 时间:2024/06/02 10:10

第几天?

Time Limit:1000MS  Memory Limit:65536K
Total Submit:99 Accepted:55

Description

给定一个日期,输出这个日期是该年的第几天。

Input

输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,另外,可以向你确保所有的输入数据是合法的。

Output

对于每组输入数据,输出一行,表示该日期是该年的第几天。

Sample Input

1985/1/202006/3/12

Sample Output

2071

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);                }            }        }    }


0 0
原创粉丝点击