Gym 100625A Spy Car Rental problem-simple simulation-(use of map)

Source: Internet
Author: User

Test instructions: Enter a variety of car accident compensation price, car rental start price, per kilometer, enter a number of multi-personal events (car rental, car, accident), the name of the dictionary output per person's total cost, if the information is incomplete or illegal output "inconsitent" (car rental, accidents, the order of the car is right, A person in the same period can not rent more than a car, rental car to complete not only rent or not rent but also)

Analysis: The problem is a simple simulation, complex in I do not know how to use string to do the keyword, know the map, everything is good to run. Little trick: A person can rent a car more than once.

Code:

#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <string > #include <cstring> #include <map>using namespace std;int t,n,m;struct node1{int a,b,c;};    struct node2{int time;    String A, B;    int State,ans;    string car; Node2 (int state=0,int ans=0): State, ans (ans) {}};map<string,node1> car;map<string,node2> man;int    Main () {cin>>t;        while (t--) {car.clear ();        Man.clear ();        cin>>n>>m;        string S;        int a,b,c;            while (n--) {cin>>s>>a>>b>>c;            Car[s].a=a;            Car[s].b=b;        Car[s].c=c;        } string x, Y, Z;            while (m--) {cin>>a>>x>>y>>z;            Man[x].a=y,man[x].b=z; if (man[x].state!=-1) {if (y== "P") {if (man[x].state==0| |                  man[x].state==2) {man[x].state=1;      Man[x].car=z;                    man[x].ans+=car[z].b;                    } else{Man[x].state=-1; }} else if (y== "R") {if (man[x].state==1) {MAN[X].S                        tate=2;                        int ans=0;                        for (int i=0;i<z.size (); i++) {ans=ans*10+ (z[i]-' 0 ');                    } man[x].ans+=ans*car[man[x].car].c;                } else Man[x].state=-1;                        } else if (y== "a") {if (man[x].state==1) {int ans=0;                        for (int i=0;i<z.size (); i++) {ans=ans*10+ (z[i]-' 0 ');                    } man[x].ans+= (int) ceil ((double) ans*car[man[x].car].a/100);                } else Man[x].state=-1;    }        }} Map<string,node2>::iterator it; For (It=man.begin (); It!=man.end (); it++) {if ((*it). second.state!=2)) cout<< (*it) .first<< "Inconsiste            NT "<<endl;        else cout<< (*it) .first<< "" << (*it) .second.ans<<endl; }    }}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Gym 100625A Spy Car Rental problem-simple simulation-(use of map)

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.