CODE[VS] 2008 你已经爱我多久了

题目描述 Description

小A和小B是一对情侣,并且他们都喜欢数学。向其他恋爱中的女孩一样,小B总是喜欢问小A一些奇怪的问题。 今天,小B问小A:“你已经爱我多久了。”并要他马上回答。小A将会给他一个数字(小A已经爱小B多少秒了。)你能帮助小B计算现在的时间吗?

输入描述 Input Description

第一行有如下的一个时间“YYYY/MM/DD hh:mm:ss”(小A和小B在一起的开始时间)和小A给小B的时间T。(所有的输入时间都在2000年以后)

输出描述 Output Description

以下面的格式输出现在的时间 "YYYY/MM/DD hh:mm:ss"。

样例输入 Sample Input

2000/12/31 23:59:59 3

样例输出 Sample Output

2001/01/01 00:00:02

数据范围及提示 Data Size & Hint

60%的数据中0<=T<=5*10^6;

100%的数据中0<=T<=10^12;

我真的爱上海琴烟了。

wlop太赞了。

纯模拟。

30分代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<algorithm>
 5 #include<cstring>
 6 using namespace std;
 7 
 8 int year1,month1,day1,hour1,minute1,second1;
 9 int year2,month2,day2,hour2,minute2,second2;
10 long long t;
11 
12 int main()
13 {
14     scanf("%d/%d/%d %d:%d:%d %lld",&year1,&month1,&day1,&hour1,&minute1,&second1,&t);
15     second2=(second1+t)%60;
16     minute2=(second1+t)/60+minute1;
17     int x=minute2/60;
18     minute2%=60;
19     hour2=hour1+x;
20     x=hour2/24;
21     hour2%=24;
22     day2=day1+x;
23     if(month1==1||month1==3||month1==5||month1==7||month1==8||month1==10||month1==12)
24     {
25         x=day2/31;
26         day2%=31;
27         if(day2==0)
28         {
29             day2=31;
30             x--;
31         }            
32     }    
33     else if(month1!=2)
34     {
35         x=day2/30;
36         day2%=30;
37         if(day2==0)
38         {
39             day2=30;
40             x--;
41         }    
42     }
43     else if(year1%4==0)
44     {
45         x=day2/29;
46         day2%=29;
47         if(day2==0)
48         {
49             day2=29;
50             x--;
51         }
52                 
53     }    
54     else 
55     {
56         x=day2/28;
57         day2%=28;
58         if(day2==0)
59         {
60             day2=28;
61             x--;
62         }    
63     }    
64     month2=month1+x;
65     x=month2/12;
66     month2%=12;
67     if(month2==0) month2=12;
68     year2=year1+x;
69         printf("%4d/%02d/%02d %02d:%02d:%02d",year2,month2,day2,hour2,minute2,second2);
70 }
因为特殊情况比较多,全都按共性处理不可行

ac代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #define ll long long
 4 using namespace std;
 5 ll a,b,c,d,e,f,x;
 6 char o,p,r,s;
 7 int mouth1[13]= {0,31,29,31,30,31,30,31,31,30,31,30,31};
 8 int mouth2[13]= {0,31,28,31,30,31,30,31,31,30,31,30,31};
 9 int main()
10 {
11     cin>>a>>o>>b>>p>>c>>d>>r>>e>>s>>f>>x;
12     f=f+x;
13     if(f>=60)
14     {
15         e=e+f/60;
16         f=f%60;
17     }
18     if(e>=60)
19     {
20         d=d+e/60;
21         e=e%60;
22     }
23     if(d>=24)
24     {
25         c=c+d/24;
26         d=d%24;
27     }
28     while(1)
29     {
30         int falg=0;
31         if((a%4==0&&a%100!=0)||(a%400==0))
32         {
33             for(int i=b; i<=b+12; i++)
34             {
35                 if(i==13)a++;
36                 if(c>mouth1[i%13])c=c-mouth1[i%13];
37                 else
38                 {
39                     falg=1;
40                     b=i%13;
41                     break;
42                 }
43             }
44         }
45         else
46         {
47             for(int i=b; i<=b+12; i++)
48             {
49                 if(i==13)a++;
50                 if(c>mouth2[i%13])c=c-mouth2[i%13];
51                 else
52                 {
53                     falg=1;
54                     b=i%13;
55                     break;
56                 }
57             }
58         }
59         if(falg)break;
60     }
61     cout<<a<<o;
62     if(b<10)cout<<"0"<<b<<p;
63     else cout<<b<<p;
64     if(c<10)cout<<"0"<<c<<" ";
65     else cout<<c<<" ";
66     if(d<10)cout<<"0"<<d<<r;
67     else cout<<d<<r;
68     if(e<10)cout<<"0"<<e<<s;
69     else cout<<e<<s;
70     if(f<10)cout<<"0"<<f;
71     else cout<<f;
72 }
还有判断闰年的方法要注意。巧用数组。

猜你喜欢

转载自www.cnblogs.com/Mary-Sue/p/9160337.html
今日推荐