-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprob_00380.cpp
69 lines (65 loc) · 1.84 KB
/
prob_00380.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <climits>
#include <iomanip>
#include <bitset>
using namespace std;
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vi>
#define vvii vector<vii>
#define ll long long
#define sc(n) scanf("%d",&n)
#define scc(n,m) scanf("%d%d",&n,&m)
#define repf(i,a,b) for(i=a;i<b;++i)
typedef struct Forwarding{
int start,end,destination;
Forwarding(int s,int d, int des):start(s),end(d),destination(des){}
}forwarding;
map<int,vector<forwarding> > database;
int get_ext(int time,int src,int ext){
if(ext==src) return 9999;
for(auto&val:database[src])
if(time>= val.start && time<= val.end)
return get_ext(time,val.destination,ext);
return src;
}
int aux(int time, int source){
for(auto&val: database[source]){
if(time>=val.start && time<= val.end)
return get_ext(time,val.destination,source);
}
return source;
}
int main(){
int i,j,k,l,ext,source,x,duration,destination,t;
sc(t);
printf("CALL FORWARDING OUTPUT\n");
repf(l,1,t+1){
database.erase(database.begin(),database.end());
while(sc(source),source){
scanf("%d%d%d",&x,&duration,&destination);
if(database.find(source)==database.end())
database[source]= vector<forwarding>{};
database[source].push_back(forwarding(x,(x+duration)%8784,destination));
}
printf("SYSTEM %d\n",l);
while(sc(x),x!=9000){
sc(ext);
int dest= aux(x,ext);
printf("AT %04d CALL TO %04d RINGS %04d\n",x,ext,dest);
}
}
printf("END OF OUTPUT\n");
}