1016 Phone Bills

题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805493648703488

代码有点问题,过不了测试样例,先贴出来,有空改,代码如下:

  1 #include<iostream>
  2 #include<cstring>
  3 #include<algorithm>
  4 #include<queue>
  5 #include<cstdio>
  6 #include<fstream>
  7 using namespace std;
  8 const string online = "on-line";
  9 const string offline = "off-line";
 10 float rate[24];
 11 struct infor{
 12     string name;
 13     string time;
 14     string line;
 15     int bianhao;
 16     int h;
 17     int m;
 18     int s;
 19     int he;
 20     void init(){
 21         bianhao = (int)((time[0]-'0')*10)+(int)(time[1]-'0');
 22         h = (int)((time[3]-'0')*10)+(int)(time[4]-'0');
 23         m = (int)((time[6]-'0')*10)+(int)(time[7]-'0');
 24         s = (int)((time[9]-'0')*10)+(int)(time[10]-'0');
 25     }
 26     void qiuhe(){
 27         he = h*3600+m*60+s;
 28     }
 29     friend bool operator <(const infor &in1,const infor &in2){
 30         if(in2.bianhao < in1.bianhao) return true;
 31         else if(in2.h > in1.h) return true;
 32         else if(in2.m > in1.m) return true;
 33         else if(in2.s > in1.s) return true;
 34         else return false;
 35     }
 36 };
 37 bool comp(string s1,string s2){
 38     return s1 < s2;
 39 }
 40 bool fin(string s[],string a,int x){
 41     for(int i = 0; i < x; i++){
 42         if(s[i] == a) return true;
 43     }
 44     return false;
 45 }
 46 int sum(int a1,int a2){
 47     //cout << a1-a2;
 48     return a1-a2;
 49 }
 50 float qianshu(int x,int y,int j,int i){                 //2 1 2 1
 51     int stem=0;
 52     if(i == j) return ((x-y)*rate[i])/100.0;
 53     else if(i == j-1) return ((j*7000-y)*rate[i]+(x-j*7000)*rate[j])/100.0;
 54     else{
 55         for(int k = j-i; k>=1; k--){
 56             stem += (i+1)*3600+rate[i+1];
 57         }
 58         stem += (j*7000-y)*rate[i]+(x-j*7000)*rate[j];
 59         return stem/100.0;
 60     }
 61 }
 62 int main(){
 63     priority_queue<infor> q1;
 64     priority_queue<infor> q2;
 65     string per[501];
 66     freopen("in.txt","r",stdin);
 67     float qian[501];
 68     int n,count = 0, cou = 0,shu=0;
 69     for(int i = 0; i < 24; i++){
 70         scanf("%f",&rate[i]);
 71     }
 72     scanf("%d",&n);
 73     infor stem[1003];
 74     while(n--){
 75         cin >> stem[cou].name >> stem[cou].time >> stem[cou].line;
 76         //int st = per.find(stem[cou].name);
 77         if(!fin(per,stem[cou].name,count)) per[count++] = stem[cou].name;
 78         stem[cou].init();
 79         stem[cou].qiuhe();
 80         cou++;
 81         //q.push(stem);
 82     }
 83     sort(per,per+count,comp);
 84     for(int i = 0; i < count; i++){
 85         cout << per[i] << endl;
 86     }
 87     for(int i = 0; i < count; i++){
 88         for(int j = 0; j < cou; j++){
 89             if(per[i] == stem[j].name && stem[j].line == online){
 90                 q1.push(stem[j]);
 91             }
 92             else if(per[i] == stem[j].name && stem[j].line == offline){
 93                 q2.push(stem[j]);
 94             }
 95         }
 96         float qiansh = 0;
 97         for(int i = 0; i < q2.size(); i++){
 98             while(q2.top().bianhao != q1.top().bianhao) q1.pop();
 99             cout << per[i] << " " << q2.top().bianhao << endl;
100             cout << q1.top().h << ":" << q1.top().m << ":" << q1.top().s << " "
101                 << q2.top().h << ":" << q2.top().m << ":" << q2.top().s << " ";
102             int he_stem = sum(q2.top().he,q1.top().he);
103             float qian = qianshu(q2.top().he,q1.top().he,q2.top().h,q1.top().h);
104             cout << he_stem << " " <<  "$" << qian << endl;
105             qiansh += qian;
106         }
107         cout << "Total amount:" << "$" << qiansh << endl;
108         while(!q1.empty()) q1.pop();
109         while(!q2.empty()) q2.pop();
110     }
111     return 0;
112 }

 

posted @ 2018-10-08 16:27  琥琥笙威  阅读(393)  评论(0编辑  收藏  举报