zoukankan      html  css  js  c++  java
  • hdu 1861 游船出租 tag:模拟

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1861     一个研究生入学考试上机题==b

    思路: 将信息放在结构体里,然后存在向量中, 最后扫描到n==0就统计,输出,清空向量。  

    需要注意的是 1 同一艘船可能出租两次,于是扫描到op=='E' 时,就要立马处理。

                             2 扫描到 op=='E' 时 ,还要看是否有S的记录,如果没有找到就不处理

                             3 从00:00 -> 00:00 算是借了一分钟~   而不是差值0分钟

                             4 字符串和整数之间转化   用stringstream ,#include <sstream>

     代码:

    #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 ave=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);
    
    
                  // 分钟计算小心一点
    
                  if(startminute<=endminute)
                  ave+=stringtoint(endminute)-stringtoint(startminute);
                  else
                  {
                   ave+=stringtoint(endminute)-stringtoint(startminute)+1;
    
                  }
    
                   ave+=(stringtoint(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);
    
         }
      }
    }
    

  • 相关阅读:
    windows已经阻止此软件因为无法验证发行者解决方案
    vs用resharp如何调试到源码而不是对象浏览器
    Android环境变量的设置(详细图解版)
    js为xml添加节点和属性
    javascript操作xml文件综合实例
    js如何循环读取xml文件的节点
    游标的简单理解
    关于DATE函数datediff dateadd datename等
    分组数据where & having ,group by & order by
    SQL拼接字段,算数计算
  • 原文地址:https://www.cnblogs.com/814jingqi/p/3247187.html
Copyright © 2011-2022 走看看