一道水模拟,电话呼叫转移,题目又读了半天,开始刚以为是图论神马的,结果发现想太多了,直接枚举
#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;
}