Uncle Hey

Problem Description

The annual GaoDaoKuOI(GDKOI), an interesting programming contest, was held several weeks ago. Uncle Hey had been supposed to 
be a judge, but turned out to be a scheduler, which annoyed him very much. What's going on?
During the contest, contestants might want to go out for a break. (Don't ask why they have such a privilege. They do have anyway) 
However, it is not allowed that two or more contestants went out together. So, they had to go one by one, that is, First Come First Served. 
In case that two or more contestants posted their requests at the same time, you could safely assume that one with the lexicographically 
smaller name came earlier.
It's an annoying job, isn't it? So, Uncle Hey wants to share the annoyance with you guys here. Given the record of all requests like this:
T1C1D1
T2C2D2
……
TnCnDn
Each line describe a request, where T1 represents the posting time of the request, and C1 represents the name of the contestant who posted
 the request, and D1 means how long will it take for he/she to go out and come back. Note that, requests are given in no order.
You're supposed to report all events like this: "xxx went out at time yyy" (quotes for clarity), where xxx represents the name of the contestant
 and yyy is the time when he/she was permitted to go. You should print the events in non-decreasing order of the happending time. Please
 refer to the sample for more information.

Input

First line contains an integer M(M<=6), indicating the number of test cases.
Each test case is in the format like this:
First comes a positive integer N(N<=10000), indicating the number of requests. Then N lines follows. Each line contains a positive integer T, 
a string C and a positive integer D, representing a request, T<=10000000, D<=1000, C contain no more than 20 lowercase letters.
It's guaranteed that there are no two requests share a same name.(begini<endi<=32767)

Output

For each test case, print all events in the order described as above, one event per line. print a blank line after each test case.

Sample Input

2
1
10 lg 5
2
10 lg 5
5 wing 6

Sample Output

lg went out at time 10

wing went out at time 5

lg went out at time 11

#include<cstdio>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;
struct mad
{
    int T;//请求发布的时间
    string name;//名字
    int C;//回来(出去)的时间
};
int cmp(mad x, mad y)
{
    if(x.T != y.T) return x.T < y.T;
    else return x.name < y.name;
}
int main()
{
    int n, m;
    mad a[10005];
    while(scanf("%d", &m) != EOF)
    {
        while(m--)
        {
            scanf("%d", &n);
            for(int i = 0; i < n; i++)
                cin >> a[i].T >> a[i].name >> a[i].C;
            sort(a, a + n, cmp);//排升序(可以统计多次请求的次数)
            for(int i = 0; i < n; i++)
            {
                if((a[i].T + a[i].C) > a[i + 1].T)  
                         a[i + 1].T = a[i].T + a[i].C;//每个人可以开始休息的时间
                cout << a[i].name << " went out at time " << a[i].T << endl;
            }
            printf("\n");
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值