C++编程:Call Forwarding

来源:互联网 发布:sqlserver培训中心 编辑:程序博客网 时间:2024/06/03 20:29

题目描述:


 Thanks to computer technology the functionality of phone systems has been greatly enhanced in the last ten years. We have automated menus, sophisticated answering machines, conference call capabilities, group addressing and so on. A common feature of a company's phone system is the ability to set call forwarding. For example, if Bob at the Nobody's Home Company (NHC) goes on vacation, he sets things up so that all calls coming to him are forwarded to his associate Jane. This problem addresses how phone systems might keep track of call forwarding.

 

The phones at the NHC all have four digit extensions. Employees can set call forwarding by entering the appropriate information through their telephone interface. If an employee is going to be away they enter the following information: their extension, the time they are leaving, how long they will be away, and the extension that their calls should be forwarded to, with the following constraints:

 

  • All extensions consist of four digits.
  • The extensions 0000 and 9999 are reserved for special use and will not be entered as information by an employee.
  • Times are recorded in increments of 1 hour and are based on a clock that begins at 0000 at midnight every New Year's Eve. Therefore, when describing the time they are leaving, employees always use an integer between 0000 and 8784 (which is 366*24). The call forwarding system is completely reset at the beginning of the year.
  • A call forward set to start at time X for a duration of Y will be in effect from time X to time X+Y inclusive.

Users are ``good" about the requests they enter. They follow the format rules. They do not enter a request such that the duration of the request would go past the end of the year. They do not enter two requests for their extension that overlap in time. Even though the users enter correct, clear, non-overlapping information from their own point of view, a degenerate situation can still occur in a call forwarding system, if requests have been made in such a way as to forward a call back to the original target of the call. For example if Bob forwards his calls to Sue, and Sue forwards her calls to Joe, and Joe forwards his calls to Bob then when somebody calls any of these three people their calls would be forwarded forever. To prevent this situation the call forwarding system uses the ``dead end" number 9999. Any calls made to an extension involved in such a degenerate situation will be forwarded to the special 9999 extension.


输入样例:


21111 0100 0200 22221111 0301 0500 44442222 0200 0200 33333333 0250 1000 11117777 1000 2000 777700000050 11110150 11110200 11110225 22220270 11110320 11110320 33330900 30001250 33331250 7777900000003000 11119000

输出样例:


CALL FORWARDING OUTPUTSYSTEM 1AT 0050 CALL TO 1111 RINGS 1111AT 0150 CALL TO 1111 RINGS 2222AT 0200 CALL TO 1111 RINGS 3333AT 0225 CALL TO 2222 RINGS 3333AT 0270 CALL TO 1111 RINGS 9999AT 0320 CALL TO 1111 RINGS 4444AT 0320 CALL TO 3333 RINGS 4444AT 0900 CALL TO 3000 RINGS 3000AT 1250 CALL TO 3333 RINGS 1111AT 1250 CALL TO 7777 RINGS 9999SYSTEM 2AT 3000 CALL TO 1111 RINGS 1111END OF OUTPUT

输入描述:


 The first line contains an integer N between 1 and 10 describing how many call forwarding systems will be simulated by your program. Each call

forwarding system will be represented by 0 to 100 `source time duration target' lines. These lines represent the requests by the users to set up a 

call forwarding from the `source' to the `target' starting at the `time' for a length of `duration', and will be in the form `dddd dddd dddd dddd'. A line 

with 0000 in the `source' position indicates the end of this portion of the input. The call forwarding requests are listed in the order received. They will 

be followed by 1 or more `time extension' lines, in the form `dddd dddd', in non-decreasing order by `time' representing calls made into the system at 

`time' to `extension'. A line with 9000 in the `time' position indicates the end of this portion of the input.


输出描述:


 The first line of output must read CALL FORWARDING OUTPUT. This will be followed by sections of information about each of the call forwarding systems

being simulated. Each of these sections should be headed by the line SYSTEM N, where N is the number (1, 2, ...) of the system. Within the section there 

should be a line describing the result of each of the calls made into the system, with the format ``AT dddd CALL TO dddd RINGS dddd". The final line of 

output should read END OF OUTPUT.


程序限制:


程序可使用最大内存:

50240K

程序运行最长耗时:

5000MS(毫秒)
解题思路:号码是规定的4个字符,电话可以随意转接,但是范围与(number[i][1]<=str<=number[i][1]+number[i][2])中间两个号码有关系。死扣这个关系,本题就变得简单了。
代码:
#include <iostream>#include <string>#include <cstring>#include <stdlib.h>using namespace std;string number[1000][4];string str2;int sum;string change(string str,int k){string str3;cin>>str2;str3=str2;bool ft=true;int i,p=0,num,num1,num2;while(p<k+2 && ft==true){ft=false;for(i=0;i<k;i++){num=atoi(str.c_str());num1=atoi(number[i][1].c_str());num2=atoi(number[i][2].c_str());if(str3==number[i][0] && num>=num1 && num<=(num1+num2)){p++;ft=true;str3=number[i][3];}}}if(p>=k+2) str3="9999";return str3;}int main(){int n,i,j;cin>>n;cout<<"CALL FORWARDING OUTPUT"<<endl;for(i=1;i<=n;i++){string str;j=0;while(cin>>str && str != "0000"){number[j][0]=str;cin>>number[j][1]>>number[j][2]>>number[j][3];j++;}sum=j;cout<<"SYSTEM "<<i<<endl;string str1;while(cin>>str1 && str1 != "9000"){cout<<"AT "<<str1<<" CALL TO ";string musics=change(str1,sum);cout<<str2<<" RINGS "<<musics<<endl;}}cout<<"END OF OUTPUT"<<endl;return 0;}
                                             
0 0