pascal编程 有关字符串的

来源:百度知道 编辑:UC知道 时间:2024/05/21 11:28:03
Description

给定一个具体的日期,请输出,这一天是当年的第几天?

Input

输入格式如下,
year-month-day
如:
1999-9-9
代表1999年9月9日

Output

输入,这一天为那一年的第多少天

Sample Input

2000-1-31

Sample Output

31

var
t1:array[1..12] of longint=(0,31,60,91,121,152,182,213,244,274,305,335); //闰年1月1日到12月1日前的天数
t2:array[1..12] of longint=(0,31,59,90,120,151,181,212,243,273,304,334); //平年1月1日到12月1日前的天数
a:array[1..3] of longint; //年、月、日
sum,i,t:longint; //sum为总天数
s:string;
begin
readln(s);
t:=1;
for i:=1 to length(s) do
begin
if s[i]<>'-' then a[t]:=a[t]*10+ord(s[i])-ord('0'); //储存年、月、日
if s[i]='-' then inc(t);
end;
if (a[1] mod 4=0) and (a[1] mod 100<>0) or (a[1] mod 400=0) then //判断是否为闰年
sum:=sum+t1[a[2]]+a[3]
else
sum:=sum+t2[a[2]]+a[3];
writeln(sum);
end.