Journey to the company lay a solid foundation --P1615

Topic links: https://www.luogu.org/problem/P1615

P1615 Journey Company

Topic background

An extremely nonsensical topics

Title Description

What happened was this: Journey to the Sun Sha Zhu (Sun butcher) after three Buddhist sutras, apprentice entered the Xiamen University to study economics and trade, after one hour of learning, they graduate to use violent means. Then, they founded three companies - "Flower and Fruit Mountain Ecological Tourism Resort Group" "Gao Village pork Food City Limited" "Ferry Co., Ltd. Liu Shahe." Although the three companies from the "scrolls Press" Zang president's disciples, but remained below 0 yuan of fiscal revenue. So they came up with a boring method - steal from others! Is this: If you know Pig Pig Monkey King to steal pans, Pig will not try to steal the Porsche Shahe Shang. Now, as men Pig chief intellectual disabilities (intellectual disabilities) you, to help both smart and stupid pig with the kind of unfair means to save the company! You can do this: You have to know when the Monkey King to come steal the pig, and the pig but also at what time to grab something Shahe Shang, Pig and know Shahe Shang 1 steal per second laptop, to help the pig count a calculation that he can within a limited time to steal sand monk how many computers so that he has enough time to defend against big Brother.

Input Format

First line: hours: minutes: seconds (expressed intention to steal time Shahe Shang Pig laptop)

Second row: hours: minutes: seconds (time indicates intention Monkey Pig steal pan)

Note: The time may have leading 0, there may be no.

Third row: Pig can steal second Shahe Shang several laptops

Ensure that the time of the first row of the second row than the time come early.

Output Format

An integer, may be greater than int (2 ^ 31-2), pig represents the number of the notebook could steal sand monk

Sample input and output

Input # 1
00:0:00
0:00:10
10
Output # 1
100

Description / Tips

data range:

00:00:00 to 23:59:59

Number <= 32767

This question is quite basis of a question, the main test of your programming ideas, and some simple simulation. How the subject is not difficult, with emphasis on input ignored when leading 0! ! !

But here I want to want complicated, wrote a function to handle the leading 0, but I think the solution to a problem with the bigwigs practice is when you deal directly with the input of leading 0, more than the simple practice I use , so I went with the chiefs of the practice and wrote the code (* ^ ▽ ^ *)

Man of few words said on the code:

Leading zero processing function:

. 1 #include <the iostream>
 2 #include <CString>
 . 3  
. 4  the using  namespace STD;
 . 5  
. 6  String A, b representative of Pig // A intends to steal time sand monk laptop, b representative of time Monkey Pig intends to steal pan
 . 7  
. 8  Long  Long n-; // n-pig steal per second is the number of computer sand monk
 . 9  
10  int AA, BB; // convert to seconds
 . 11  
12 is  void T ( String X, int & Y) // preamble processing 0
 13 is  {
 14      int len = x.size (), V = 0 ;
 15      for ( int I = 0 ; I <len; I ++)
16     {
17         if(x[i]==':')
18         {
19             v++;
20             int m=0,k=1;
21             for(int j=i-1;j>=0;j--)
22             {
23                 if(x[j]==':') break;
24                 m+=(x[j]-'0')*k;
25                 k*=10;
26             }
27             if(v==1) y+=m*3600;
28             else if(v==2) y+=m*60;
29         }
30     }
31     int m=0; v=1;
32     for(int i=len-1;i>=0;i--)
33     {
34         if(x[i]==':') break;
35         m+=(x[i]-'0')*v;
36         v*=10;
37     }
38     y+=m;
39 }
40 
41 int main()
42 {
43     cin>>a>>b>>n;
44     t(a,aa);
45     t(b,bb);
46     cout<<(bb-aa)*n<<endl;
47     return 0;
48 }

 

Bigwigs approach:

 1 #include<iostream>
 2 #include<cstdio>
 3 
 4 using namespace std;
 5 
 6 long long a,b,c,d,e,f,g,n;
 7 
 8 int main()
 9 {
10     scanf("%d:%d:%d",&a,&b,&c);
11     scanf("%d:%d:%d",&e,&f,&g);
12     scanf("%d",&n);
13     cout<<((e-a)*3600+(f-b)*60+g-c)*n<<endl;
14     return 0;
15 }

*** solemnly Tip:

· Scnaf automatically ignores the leading 0! ! ! ! (This question test sites)

 

Lay a solid foundation, do a good job each question! ! !

Author: Gmax

 

This article belongs to the author and blog Park total, reproduced, please use the link, please do not reprint the original, Thanks ♪ (· ω ·) Techno

2019-08-08

Guess you like

Origin www.cnblogs.com/Gmax/p/11319114.html