HDU 1861 cruise ship rental tag: Simulation

Source: Internet
Author: User

Question address: http://acm.hdu.edu.cn/showproblem.php? PID = 1861 one postgraduate entrance exam computer question = B

Train of Thought: place the information in the struct, then exist in the vector, and finally scan to n = 0 for statistics, output, and clear the vector.

It should be noted that a single ship may be rented twice, so when scanning op = 'E', it should be handled immediately.

2. When op = 'E' is scanned, check whether there is a s record. If no record is found, it will not be processed.

3. I borrowed one minute from-> ~ Instead of 0 minutes

4. Use stringstream to convert strings and integers. # include <sstream>

Code:

# Include <iostream> # include <string> # include <vector> # include <map> # include <sstream> # include <cmath> using namespace STD; struct info {int number; char op; string time ;}; int stringtoint (string s) {int ans; stringstream SS; SS <s; SS> ans; return ans;} int main () {int N; vector <info> V; while (CIN> N) {info theinfo; char op; CIN> op; string time; CIN> time; if (n =-1) break; If (n = 0) {int COUNT = 0; double AV E = 0; Map <int, string> Start; Map <int, string> end; For (INT I = 0; I <v. size (); I ++) {If (V [I]. OP ='s ') Start [V [I]. number] = V [I]. time; else if (V [I]. OP = 'E' & start. find (V [I]. number )! = Start. end () {count ++; string starthour = start. find (V [I]. number)-> second. substr (0, 2); string startminute = start. find (V [I]. number)-> second. substr (3, 2); string endhour = V [I]. time. substr (0, 2); string endminute = V [I]. time. substr (3, 2); // minute-level computing caution if (startminute <= endminute) Ave + = stringtoint (endminute)-stringtoint (startminute); else {Ave + = stringtoint (endminute) -stringtoint (startminute) + 1;} Ave + = (stringto INT (endhour)-stringtoint (starthour) * 60 ;}} v. Clear (); If (count! = 0) Ave = Ave/count; cout <count <"" <floor (AVE) <Endl;} else {theinfo. time = time; theinfo. number = N; theinfo. OP = op; V. push_back (theinfo );}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.