ZOJ-1282

41 篇文章 0 订阅

一道水模拟,电话呼叫转移,题目又读了半天,开始刚以为是图论神马的,结果发现想太多了,直接枚举

#include<cstdio>
#include<vector>
#include<map>
#include<iostream>
#include<string>
#include<cstdlib>

using namespace std;

struct Call
{
    int start, end;
    string target;
};

int main()
{
    int N;
    cin >> N;
    map<string, vector<Call *> > M;
    puts("CALL FORWARDING OUTPUT");
    for (int t = 1; t <= N; t++)
    {
        printf("SYSTEM %d\n", t);
        string source, target;
        int time, dur;
        M.clear();
        while (cin >> source, source != "0000")
        {
            cin >> time >> dur >> target;
            Call *call = new Call();
            call->start = time;
            call->end = time + dur;
            call->target = target;
            if (M.find(source) == M.end())
            {
                vector<Call *> v;
                v.push_back(call);
                M[source] = v;
            }
            else
                M[source].push_back(call);
        }
        string stime;
        while (cin >> stime, stime != "9000")
        {
            cin >> source;
            time = atoi(stime.c_str());
            string now = source;
            while (M.find(now) != M.end())
            {
                vector<Call *> v = M[now];
                bool find = false;
                for (size_t i = 0; i < v.size(); i++)
                    if (time >= v[i]->start && time <= v[i]->end)
                    {
                        find = true;
                        now = v[i]->target;
                        break;
                    }
                if (!find)
                    break;
                else if (now == source)
                {
                    now = "9999";
                    break;
                }
            }
            printf("AT %s CALL TO %s RINGS %s\n", stime.c_str(), source.c_str(),
                   now.c_str());
        }
    }
    puts("END OF OUTPUT");
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值