首页 > 其他分享 >杭电1201

杭电1201

时间:2023-02-06 21:02:09浏览次数:51  
标签:int 18 sum 1201 month 杭电 year 生日


18岁生日

Problem Description
Gardon的18岁生日就要到了,他当然很开心,可是他突然想到一个问题,是不是每个人从出生开始,到达18岁生日时所经过的天数都是一样的呢?似乎并不全都是这样,所以他想请你帮忙计算一下他和他的几个朋友从出生到达18岁生日所经过的总天数,让他好来比较一下。

Input
一个数T,后面T行每行有一个日期,格式是YYYY-MM-DD。如我的生日是1988-03-07。

Output
T行,每行一个数,表示此人从出生到18岁生日所经过的天数。如果这个人没有18岁生日,就输出-1。

Sample Input
1
1988-03-07

Sample Output
6574

代码:

# include <iostream>
# include <cstdio>
# include <algorithm>
using namespace std;

int f(int year){
if((year%4==0&&year%100!=0)||year%400==0){
return 1;
}else{
return 0;
}
}

int main(){

int n,i,j;
int year,month,day;

scanf("%d",&n);
while(n--){
int sum = 0;
scanf("%d-%d-%d",&year,&month,&day);
if(month==2 && day==29){
printf("-1\n");

}else{
sum = 365*18;
for(i=1;i<18;i++){
sum+=f(i+year);
}

if(month<=2){//对头0年的判断
sum+=f(year);
}else{//对最后一年的判断 第19年
sum+=f(year+18);
}
printf("%d\n",sum);
}

}


return 0;
}


标签:int,18,sum,1201,month,杭电,year,生日
From: https://blog.51cto.com/u_15955675/6040511

相关文章

  • 杭电1202--学分
    ThecalculationofGPATimeLimit:2000/1000MS(Java/Others)MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):24013AcceptedSubmission(s):5610P......
  • 杭电1205--吃糖
    吃糖果ProblemDescriptionHOHO,终于从Speakless手上赢走了所有的糖果,是Gardon吃糖果时有个特殊的癖好,就是不喜欢将一样的糖果放在一起吃,喜欢先吃一种,下一次吃另一种,这样;可......
  • 杭电1163--9余项定理的例子
    #include<iostream>#include<cstdio>#include<algorithm>usingnamespacestd;intmain(){intn,a[10009];inti,t;while(scanf("%d",&n),n!=0){......
  • 杭电1028
    IgnatiusandthePrincessIIIProblemDescription“Well,itseemsthefirstproblemistooeasy.Iwillletyouknowhowfoolishyouarelater.”feng5166says......
  • 杭电1085
    ​​这里写链接内容​​HoldingBin-LadenCaptive!TimeLimit:2000/1000MS(Java/Others)MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):13861A......
  • 杭电1398
    SquareCoinsProblemDescriptionPeopleinSilverlandusesquarecoins.Notonlytheyhavesquareshapesbutalsotheirvaluesaresquarenumbers.Coinswithva......
  • 杭电2073
    ​​http://acm.hdu.edu.cn/showproblem.php?pid=2073​​无限的路ProblemDescription甜甜从小就喜欢画图画,最近他买了一支智能画笔,由于刚刚接触,所以甜甜只会用它来画直......
  • 杭电2095(find your present (2))
    ​​这里写链接内容​​>引用块内容ProblemDescriptionInthenewyearparty,everybodywillgeta“specialpresent”.Nowit’syourturntogetyourspecialpre......
  • Codeforces1201 B Maximum Median (二分)
    Description:Youaregivenanarray aa of nn integers,where nn isodd.Youcanmakethefollowingoperationwithit:Chooseoneoftheelementsofthearray......
  • 整除的为数 杭电2099
    [1.(​​http://acm.hdu.edu.cn/showproblem.php?pid=2099%20%20%E9%97%AE%E9%A2%98%E9%93%BE%E6%8E%A5​​)]​​``这里写代码片​#include......