首页 > 试题广场 >

游船出租

[编程题]游船出租
  • 热度指数:3508 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
    现有公园游船租赁处请你编写一个租船管理系统。当游客租船时,管理员输入船号并按下S键,系统开始计时;当游客还船时,管理员输入船号并按下E键,系统结束计时。船号为不超过100的正整数。当管理员将0作为船号输入时,表示一天租船工作结束,系统应输出当天的游客租船次数和平均租船时间。     注意:由于线路偶尔会有故障,可能出现不完整的纪录,即只有租船没有还船,或者只有还船没有租船的纪录,系统应能自动忽略这种无效纪录。

输入描述:
    测试输入包含若干测试用例,每个测试用例为一整天的租船纪录,格式为:
    船号(1~100) 键值(S或E) 发生时间(小时:分钟)
    每一天的纪录保证按时间递增的顺序给出。当读到船号为-1时,全部输入结束,相应的结果不要输出。


输出描述:
    对每个测试用例输出1行,即当天的游客租船次数和平均租船时间(以分钟为单位的精确到个位的整数时间)。
示例1

输入

1 S 08:10
2 S 08:35
1 E 10:00
2 E 13:16
0 S 17:00
0 S 17:00
3 E 08:10
1 S 08:20
2 S 09:00
1 E 09:20
0 E 17:00
-1

输出

2 196
0 0
1 60
归还船只后不能重置状态,重置状态后不能通过,所以测试的逻辑有问题。
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

#define N 101

typedef struct _Boat
{
	int startH, startM;
	int endH, endM;
}Boat;

int rent_time(const Boat &bt)
{
	return (bt.endH * 60 + bt.endM) - (bt.startH * 60 + bt.startM);
}

int main()
{
	Boat bts[N];
	int count = 0, total_time = 0;
	for (int i = 0; i < N; i++) bts[i].startH = bts[i].startM = bts[i].endH = bts[i].endM = -1;
	int No = 0;
	char SE;
	string str_time;
	while (cin>>No && -1 != No)
	{
		cin >> SE >> str_time;
		if (0 == No)
		{
			double avg = count > 0 ? (double)total_time / (double)count : 0;
			cout << count << " " << round(avg) << endl;
			count = 0; total_time = 0;
			for (int i = 0; i < N; i++) bts[i].startH = bts[i].startM = bts[i].endH = bts[i].endM = -1;
		}
		else
		{
			if ('S' == SE)
			{
				bts[No].startH = (str_time[0] - '0') * 10 + (str_time[1] - '0');
				bts[No].startM = (str_time[3] - '0') * 10 + (str_time[4] - '0');
			}
			else if ('E' == SE)
			{
				bts[No].endH = (str_time[0] - '0') * 10 + (str_time[1] - '0');
				bts[No].endM = (str_time[3] - '0') * 10 + (str_time[4] - '0');
				if (-1 != bts[No].startH)
				{
					++count;
					total_time += rent_time(bts[No]);
					//bts[No].startH = -1;
				}
			}
		}
		
	}
	return 0;
}

发表于 2020-02-19 17:29:15 回复(0)
不复杂,但测试用例不符合现实想法。
Python思路(已通过):
因为时间戳是按顺序来的
用字典保存对应船号的借出时间,只保存借出的,而且记录最新的那一次
在输入的过程中进行计算,如果还船(E)则看字典里有没该船的船号。如果有,则记录一个次数,把借出去的时间加起来为一个总和(之后再算平均);如果没有忽略。
如果借船(S),则更新该船号借出时间;没有该船号则添加这个记录。(意思就是如果借船只有一条,还船有多条也要计算这多条,所以记录最新借出时间才能通过)
输出的平均租出时间为四舍五入。
(吐槽时间:一开始我保存所有借出船号记录,还是在过程中查看是否还船,如果对应的船号还回来,借的记录有多条(只借不还)我从前面的删除到只剩一个,然后计算时间,加一个租 船次数,后把这条记录也删除了,因为你还回来了,要重新开始借。如果还船时无借的记录就忽略该条信息(只还不借)。然后不过,看到测试用例还要自己逆推-_-@!)

while True:
    try:
        boatRecord = {}                         #使用字典保存对应船号的借出时间
        rentNum = 0                             #租船次数
        rentTime = 0                            #租船总时间
        tempInput = input().split()             
        if tempInput[0] == '-1':                #输入为-1结束程序
            break
        while tempInput[0] != '0':              #直到输入为0结束此次测试用例
            if tempInput[1] == 'S':             #借船,则更新借出时间
                boatRecord[tempInput[0]] = list(map(int,tempInput[2].split(":")))
            else:                               #还船
                if tempInput[0] in boatRecord:     #如果之前有记录借船则计算
                    rentNum += 1
                    rentTime += 60 * (int(tempInput[2].split(':')[0]) - boatRecord[tempInput[0]][0]) + int(tempInput[2].split(':')[1]) - boatRecord[tempInput[0][1]
            tempInput = input().split()
        if rendNum != 0:                        #分母不能为0
            print('%d %d' % (rentNum,int(rentTime/rentNum+0.5)))
        else:
            print('0 0')
    except Exception:
        break

编辑于 2018-09-25 14:40:20 回复(0)

此题很***,不想说什么。还船的时候难道不用看先前的状态是否是S??

package com.speical.first;

import java.util.Arrays;
import java.util.Scanner;

/** 
* 游船出租
* 
* ***题目,不解释
* 
* 哈希思想,但是测试用例真的很***啊
* @author special
* @date 2018年1月6日 下午4:12:37
*/
public class Pro126 {
    static Node[] map = new Node[100];
    static int times, count;

    static class Node{
        char status;
        int[] time = new int[2];

        public Node(char status, String time){
            this.status = status;
            this.time = parseTime(time);
        }

        public int add(Node node){
            return (node.time[0] - time[0]) * 60 + (node.time[1] - time[1]);
        }
    }

    public static int[] parseTime(String times){
        int[] time = new int[2];
        time[0] = Integer.valueOf(times.substring(0,2));
        time[1] = Integer.valueOf(times.substring(3,5));
        return time;
    }

    public static void insert(Node node, int n){
        if(node.status == 'S'){  //如果当前是S直接更新当前船的状态
            map[n] = node;
        }else{
            if(map[n] != null){  //若果当前船是E,且不为空,就计算时间。我第二次都没开始用船,直接还船也可以?
                count++;         //且还船后,还不更新船的状态??
                times += map[n].add(node);
            }
        }
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);
        while(input.hasNext()){
            int n = input.nextInt();
            if(n == -1) break;
            char status = input.next().charAt(0);
            String time = input.next();
            if(n == 0){
                System.out.println(count + " " + (count == 0 ? 0 : (int)(times / (count * 1.0) + 0.5)));
                Arrays.fill(map, null);
                times = 0;
                count = 0;
            }else{
                Node node = new Node(status, time);
                insert(node, n - 1);
            }
        }
    }

}
发表于 2018-01-06 22:01:12 回复(0)
评测案例有问题,与题目描述不符
在评测案例里,如果一艘船租了,还了,然后又还了一次,相当于租还了2次(正确的应该是租还一次)。
比如:
1 S 00:00
1 E 01:00
1 E 02:00
0 S 00:00
-1
结果为
2 90
发表于 2017-09-06 10:32:13 回复(0)
专门去看了这个题AC的代码,S的时候不考虑该船的状态,两次S直接按最新的更新信息,只要S过,连续几次E都是有效的,完全没考虑船可不可借可不可换的状态,真是服了。
编辑于 2018-03-17 20:22:11 回复(2)
1.S,E配对成功才算一次
2.测试用例没有用"-1"结束
发表于 2018-03-09 15:44:18 回复(0)
大概没过的不止我一个,完全不知道用例什么毛病,把100个用例一个个调试了看,得出的结论大概是这个公园借的是黑珍珠号或者飞翔的荷兰人 : ) 我也想去。应该是未解之谜了
/*需要记录的数据:总共出租次数,每艘船租出的时间
  Boat中设置一个flag,为false表示未租出,输入数据时与对应船只信息进行比较
*/
#include<cstdio>
#include<vector>
#include<cstring>
using namespace std;
int TimeCal(char str[]);

struct Boat
{
    bool flag = false;
    int start = 0;    //开始租借的时间
    int duration = 0;    //该船总共借出的时间
};
int main()
{
    Boat boat[101];
    int idx;
    int count = 0;                 //记录借出的次数
    while (scanf("%d", &idx) != EOF && idx != -1)
    {
        char status[2], time[6];
        scanf("%s %s", status, time);     //分成三个if的判断
        ///////////如果idx为0,一轮输入结束,统计时间
        if (idx == 0)
        {
            int ans = 0;
            double sum = 0;
            if (count)
            {
                for (int i = 1; i <= 100; i++)
                {
                    sum += boat[i].duration;
                }
                ans = (int)(sum / count + 0.5);  //这个用来四舍五入的技巧很妙!!!
            }
            printf("%d %d\n", count, ans);  //这之后记得要初始化一遍,因为一轮输入结束了
            count = 0;
            for(int i = 0; i<101; i++)
            {
                boat[i].flag = false;
                boat[i].duration = boat[i].start = 0;
            }
            continue;
        }
        //如果输入的状态为租出,则判断该船是否未被借出,如果没有,则标记为借出,赋值借出时间
        if (strcmp(status, "S") == 0)
        {
            boat[idx].flag = true;
            boat[idx].start = TimeCal(time);
            continue;
        }
        //如果状态为,还船,判断/计算duration
        if (boat[idx].flag && strcmp(status, "E") == 0)
        {
            boat[idx].flag = false;
            boat[idx].duration += TimeCal(time) - boat[idx].start;
            count++;
            continue;
        }
    }//while
}//main

int TimeCal(char str[])
{
    int hour, min;
    hour = (str[0] - '0') * 10 + (str[1] - '0');
    min = (str[3] - '0') * 10 + (str[4] - '0');
    return hour * 60 + min;
}
发表于 2018-02-17 19:07:07 回复(1)
逆天样例,船租出去一次可以还无数次,各位别纠结了是样例问题
编辑于 2024-03-21 20:21:07 回复(0)
看到说测试有问题我就放心了
发表于 2023-02-19 14:32:41 回复(0)
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
using namespace std;

int t[101],book[101];

int main()
{
    int n,h,m;
    char state;
    while(true)
    {
        memset(t,0,sizeof(t));
        memset(book,0,sizeof(book));
        int count = 0,totaltime = 0;
        while(scanf("%d %c %d:%d",&n,&state,&h,&m) != EOF && n)
        {
            if(n == -1) break;
            if(state == 'S' && book[n] == 0)
            {
                book[n] = 1;
                t[n] = h * 60 + m;
            }
            else if(state == 'E' && book[n] == 1)
            {
                book[n] = 0;
                totaltime += h * 60 + m - t[n];
                t[n] = 0;
                count++;
            }
        }
        if(n == -1) break;
        if(count)
            cout << count << " " << int(totaltime * 1.0 / count + 0.5) << endl;
        else
            cout << 0 << " " << 0 << endl;
    }
    return 0;
}

发表于 2021-02-20 12:27:07 回复(0)
题目确实描述的不太清楚,有点坑
发表于 2020-09-06 09:04:45 回复(0)
最终AC代码如下:
#include <bits/stdc++.h>
using namespace std;
int getTime(string st, string ed){
    string s1=st.substr(0, 2), s2=st.substr(3, 2);
    int sth=stoi(s1), stm=stoi(s2); //分别得到开始的小时、分钟
    s1=ed.substr(0, 2), s2=ed.substr(3, 2);
    int edh=stoi(s1), edm=stoi(s2); //分别得到结束的小时、分钟
    return (edh*60+edm)-(sth*60+stm); //返回时间差
}
int main(){
    int i, cnt=0, cnttime=0;
    string time, str, key;
    map<string, string> mp;
    while(cin >> key){
        if(key == "-1") break;
        cin >> str >> time;
        if(key == "0"){
            if(cnt == 0) printf("%d %d\n", cnt, cnttime);
            else printf("%d %.0lf\n", cnt, 1.0*cnttime/cnt);
            cnt = cnttime = 0;
            mp.clear(); //清空
            continue;
        }
        if(str == "S") mp[key] = time; //这里注意 只要出现 'S' 那么就覆盖
        if(str == "E" && mp[key] != ""){ //还船 且信息完整
            cnt++;
            cnttime += getTime(mp[key], time);
        }
    }
    return 0;
}
主要思想是:用map存储开始的时间,键是船号,值是时间(用字符串存储)。只要还船时,对应船号对应的时间不为“”,则计算时间差。
编辑于 2020-04-28 10:38:00 回复(0)
题不咋地,用例很蠢
#include <bits/stdc++.h>
using namespace std;
int time2int(string time)
{
    int h,m;
    sscanf(time.c_str(),"%d:%d",&h,&m);
    return h*60+m;
}
int main()
{
    int no;
    vector<pair<int,pair<int,int> > > boats(101,pair<int,pair<int,int> >(0,pair<int,int>(0,-1)) );
    while(cin>>no&&no!=-1)
    {
        char choose;
        string time;
        cin>>choose>>time;
        if(no==0)
        {
            int sum=0,cnt=0;
            for(auto p:boats)if(p.first)sum+=p.second.first,cnt+=p.first;
            cout<<cnt<<" "<<(sum==0?sum:int(1.0*sum/cnt+0.5))<<endl;
            boats=vector<pair<int,pair<int,int> > >(101,pair<int,pair<int,int> >(0,pair<int,int>(0,-1)) );
            continue;
        }
        if(choose=='S')boats[no].second.second=time2int(time);
        if(choose=='E'&&boats[no].second.second!=-1)boats[no].second.first+=time2int(time)-boats[no].second.second,++boats[no].first;
    }
    return 0;
}



发表于 2020-04-14 01:38:51 回复(0)
正确逻辑的代码//但是不知道如果出现连续两个SS应该算那个,只有先S再E才算一次
#include<iostream>
(720)#include<cstring>
using namespace std;
struct boat{
	int time[20];
	char flag[20];
	int ans = 0;
}b[101];
int change(string s){
	int idex = s.find(":");
	int hour = 0,minute = 0,i;
	for(i=0;i<idex;i++){
		hour = hour*10+s[i]-'0';
	}
	for(i=idex+1;i<s.size();i++){
		minute = minute*10+s[i]-'0';
	}
	return hour*60+minute;
}
int main(){
	int num,max_num=0;
	char c;
	string s;
	int i,j;
	while(cin>>num){
		cin>>c>>s;
		double k = 0,ti = 0;
		if(num==-1){
			break;
		}
		else if(num==0){
			for(i=1;i<max_num;i++){
				if(b[i].ans>0){
					for(j=0;j<b[i].ans;j++){
						cout<<i<<" "<<b[i].flag[j]<<" "<<b[i].time[j]<<endl;
					}
				}
			}
				for(i=1;i<=max_num;i++){
	     			for(j=1;j<b[i].ans;){
	     				if(b[i].flag[j]=='E'&&b[i].flag[j-1]=='S'){
	    					k++;
	     					ti += b[i].time[j]-b[i].time[j-1];
		    				j += 2;
		    			}
		    			else if(b[i].flag[j]=='S'&&b[i].flag[j-1]=='E'){
		    				j++;
		    			}
			    		else if(b[i].flag[j]=='E'&&b[i].flag[j-1]=='E'){
			    			j += 2;
				    	}
				    	else{
				    		swap(b[i].flag[j],b[i].flag[j-1]);
				    		swap(b[i].time[j],b[i].time[j-1]);
				    		j++;
						}
				   }
				   cout<<k<<" "<<ti<<endl; 
			}
			if(k==0){
				cout<<"0 0"<<endl;
			}
			else{
				cout<<k<<" "<<(int)(ti/k+0.5)<<endl;
			max_num = 0;
			}
		}
		else{
			if(max_num<num){
				max_num = num;
			}
			int t = change(s);
			b[num].time[b[num].ans] = t;
			b[num].flag[b[num].ans++] = c;
		}
	}
}
牛客网测试通过的代码:只要有一个S,后面所有的E都加一次,用新的S的时间代替旧的S的时间
所以这逻辑有点傻
#include<iostream>
(720)#include<cstring>
using namespace std;
struct boat{
	int time[20];
	char flag[20];
	int ans = 0;
	int start=-1;
}b[101];
int change(string s){
	int idex = s.find(":");
	int hour = 0,minute = 0,i;
	for(i=0;i<idex;i++){
		hour = hour*10+s[i]-'0';
	}
	for(i=idex+1;i<s.size();i++){
		minute = minute*10+s[i]-'0';
	}
	return hour*60+minute;
}
int main(){
	int num,max_num=0;
	char c;
	string s;
	int i,j,x;
	while(cin>>num){
		cin>>c>>s;
		double k = 0,ti = 0;
		if(num==-1){
			break;
		}
		else if(num==0){
			for(i=1;i<=max_num;i++){
	     		for(j=0;j<b[i].ans;j++){
	     			if(b[i].flag[j]=='S'){
	     				b[i].start = b[i].time[j];
					 }
					 if(b[i].flag[j]=='E'){
					 	if(b[i].start!=-1){
					 		k++;
			    		 	ti += b[i].time[j]-b[i].start;
						 }
					 }
				}
			}
			if(k==0){
				cout<<"0 0"<<endl;
			}
			else{
				cout<<k<<" "<<(int)(ti/k+0.5)<<endl;
			max_num = 0;
			}
		}
		else{
			if(max_num<num){
				max_num = num;
			}
			int t = change(s);
			b[num].time[b[num].ans] = t;
			b[num].flag[b[num].ans++] = c;
		}
	}
}


发表于 2020-03-19 11:58:03 回复(0)
测试结果逻辑有问题,我的代码里面有正确的逻辑以及符合错误逻辑的代码:
#include <iostream>
(720)#include <algorithm>
#include <string>
(765)#include <vector>
using namespace std;

struct Record {
    int no;
    char tag;
    string time;
    friend istream& operator>>(istream& in, Record& r) {
        cin >> r.no;
        if(r.no != -1) {
            cin >> r.tag >> r.time;
        }
        return in;
    }
    bool operator <(const Record& b)const {
        return no < b.no;
    }
};

int timetominute(string t) {
    int minute = ((t.at(0) - '0') * 10 + (t.at(1) - '0')) * 60 +  (t.at(3) - '0') * 10 + (t.at(4) - '0');
    return minute;
}

int minustime(string a, string b) {
    int res;
    if(a > b)
        res = timetominute(a) - timetominute(b);
    else
        res = timetominute(b) - timetominute(a);

    return res;
}

void Handle(vector<Record>& arr) {
    arr.erase(arr.begin() + arr.size() - 1);//去掉最后那一行收工的记录
    stable_sort(arr.begin(), arr.end());
    int num = 0;
    int sum = 0;
    size_t i = 0;
    while(i < arr.size()) {
        if((i + 1) < arr.size()
                && (arr[i].no == arr[i + 1].no)
                &&  arr[i].tag == 'S' && arr[i + 1].tag == 'E'
          ) { //find a pair
            //测试数据有问题,只要前面有一个S后面的连续每个E都算一次/////////
            int k = i;
            ++i;
            while(i < arr.size() && arr[i].no == arr[k].no &&  arr[i].tag == 'E') {
                ++num;
                sum += minustime(arr[i].time, arr[k].time);
                ++i;
            }
            ///////////////////////////////////////////////////////////////////

            //这才是正确的逻辑////////////////////////////////////////////////
            // ++num;
            //sum += minustime(arr[i].time, arr[k].time);
            //i += 2;
            //////////////////////////////////////////////////////////////////
        } else {
            i += 1;
        }
    }

    if(num == 0)
        cout << "0 0\n";
    else {
        float res1 = (float)sum / num;
        int res = sum / num;
        if(res1 >= (sum / num + 0.5))
            ++res;

        cout << num << " " << res << endl;
    }

}

int main() {
    Record rec;
    vector<Record> arr;
    while(cin >> rec) {
        if(rec.no == -1) {
            break;
        } else {
            arr.push_back(rec);
            if(rec.no == 0) { //end of day
                Handle(arr);
                arr.clear();
            }
        }
    }
    return 0;
}


编辑于 2020-03-13 21:29:55 回复(0)
一开始看这题,哇,那么简单的逻辑,后来发现我想多了。。。
//测试用例有误
#include<iostream>
(720)#define N 101
using namespace std;
int s[N];
int e[N];
int main(){
    int id,h,m;
    char se;
    while(scanf("%d ",&id)!=EOF && id!=-1){
        scanf("%c %d:%d",&se,&h,&m);
        if(id!=0){
            int time = 60*h+m;
            if(se=='S')
                s[id]=time;
            else
                e[id]=time;
        }else{
            for(int i=1;i<101;i++){
                if(s[i]>0 && e[i]>0){
                    s[0]=s[0]+e[i]-s[i];
                    e[0]++;
                }
            }
            if(e[0]==0)
                printf("%d %d\n",0,0);
            else{
                //四舍五入
                int t=s[0]/e[0];
                int t_=(double)s[0]/(double)e[0]+0.5;
                if(t_>t)
                    t++;
                printf("%d %d\n",e[0],t);
            }
            fill(s,s+101,0);
            fill(e,e+101,0);
        }
    }
    return 0;
}


发表于 2020-03-06 11:40:44 回复(0)
看到说测试有问题就放心了
#include <iostream>
using namespace std;
class Record
{
public:
    int no;
    char RoR;
    float  hour;
    float  minute;
};
void totalborrow(Record *boats, int numbers)
{
    if(numbers==0)
    {
        cout<<0<<" "<<0<<endl;
        return;
    }
    float validtimes=0,sumtime=0;
    for(int i = 0;i<numbers-1;i++)
    {
        for(int j = i+1;j<numbers;j++)
        {
            if((boats[i].RoR=='S'&&boats[j].RoR=='E')&&(boats[i].no==boats[j].no))
            {
                validtimes++;
                sumtime = sumtime+60*(boats[j].hour-boats[i].hour)+boats[j].minute-boats[i].minute;
            }
        }
    }
    cout<<validtimes<<" "<<int(sumtime/validtimes+0.5)<<endl;
}
int main()
{
    int startb;
    int numbers = 0;
    Record *boats =  new Record[100];
    while(cin>>startb&&startb!=-1)
    {
        char emoj;
        int hour,minute;
        cin>>emoj;
        scanf("%d:%d",&hour,&minute);
        if(startb == 0)
        {
            totalborrow(boats, numbers);
            numbers = 0;
            continue;
        }
        else
        {
            boats[numbers].no = startb;
            boats[numbers].RoR = emoj;
            boats[numbers].hour = hour;
            boats[numbers].minute = minute;
            numbers++;
        }
    }
    return 0;
}

发表于 2019-10-07 00:24:33 回复(0)
#include <iostream>
using namespace std;

int main() {
    int boat[100] = { 0 };
    int hours[100] = { 0 };
    int minus[100] = { 0 };
    int end = 0;
    while (end==0) {
        for (int i = 0; i < 100; i++){
            boat[i] = 0;
            hours[i] = 0;
            minus[i] = 0;
        }
        int times = 0;
        double all_time = 0.0;
        int flag = 1;
        while (flag==1) {
            int no;
            char op;
            int hour, minu;
            cin >> no;
            if (no == -1) {
                flag = 0;
                end = 1;
            }else {
                cin >> op;
                scanf("%d:%d", &hour, &minu);
                if (no == 0) {
                    if (times == 0) {
                        cout << "0 0" << endl;
                    }else {
                        cout << times << " " << (int)(all_time / times + 0.5) << endl;
                    }
                    flag = 0;
                }else if (op == 'S'&&boat[no - 1] == 0) {
                    boat[no - 1] = 1;
                    hours[no - 1] = hour;
                    minus[no - 1] = minu;
                }else if (op == 'E'&&boat[no - 1] == 1) {
                    boat[no - 1] = 0;
                    times++;
                    all_time += (hour - hours[no - 1]) * 60 + (minu - minus[no - 1]);
                }
            }
        }
    }
    
    return 0;
}

发表于 2019-03-10 16:02:01 回复(0)
//有点无语,首先这个还船后起始时间不能更新。而且最后的输出还要四舍五入。
#include<stdio.h>
#include<malloc.h>
#include<string.h>
struct chuan{
    int begin;
    int end;
};
chuan all[101];
int get(char *a){
    int shi=(a[0]-'0')*10+a[1]-'0';
    int fen=(a[3]-'0')*10+a[4]-'0';
    return shi*60+fen;
}
int main(){

    int n,k=0,sum=0;
    for(int i=0;i<101;++i) all[i].begin=all[i].end=-1;
    while(scanf("%d",&n)!=-1&&n!=-1){
        char b[2],buf[100];
        scanf("%s%s",b,buf);
        int w=get(buf);
        if(n==0){
            if(k!=0)
            printf("%d %d\n",k,(sum+k-1)/k);
            else
             printf("0 0\n");
             sum=0;k=0;
             continue;
        }
        if(b[0]=='E'&&n!=0){
            all[n].end=w;
            if(all[n].begin!=-1){
                sum+=all[n].end-all[n].begin;
                //all[n].begin=-1;//常理来说需要重置。。
                ++k;
            }
        }
        else if(b[0]=='S'&&n!=0){
            all[n].begin=w;
        }

    }
    
    //system("pause");
    return 0;
}

发表于 2018-09-09 20:44:31 回复(0)
看到大家说题目有问题我就放心了
发表于 2018-09-04 12:28:17 回复(0)