构造层次树网络的编程的任务完成检索,怎么利用C语言的程序的编写的代码过程的方式实现

Description

In this problem, you are asked to keep track of the hierarchical structure of an organization's changing staff. As the first event in the life of an organization, the Chief Executive Officer (CEO) is named. Subsequently, any number of hires and fires can occur. Any member of the organization (including the CEO) can hire any number of direct subordinates, and any member of the organization (including the CEO) can be fired. The organization's hierarchical structure can be represented by a tree. Consider the example shown by Figure 1:

VonNeumann is the CEO of this organization. VonNeumann has two direct subordinates: Tanenbaum and Dijkstra. Members of the organization who are direct subordinates of the same member are ranked by their respective seniority. In the diagram, the seniority of such members decrease from left to right. For example Tanenbaum has higher seniority than Dijkstra.

When a member hires a new direct subordinate, the newly hired subordinate has lower seniority than any other direct subordinates of the same member. For example, if VonNeumann (in Figure 1) hires Shannon, then VonNeumann's direct subordinates are Tanenbaum, Dijkstra, and Shannon in order of decreasing seniority.

When a member of the organization gets fired, there are two possible scenarios. If the victim (the person who gets fired) had no subordinates, then he/she will be simply dropped from the organization's hierarchy. If the victim had any subordinates, then his/her highest ranking (by seniority) direct subordinate will be promoted to fill the resulting vacancy. The promoted person will also inherit the victim's seniority. Now, if the promoted person also had some subordinates then his/her highest ranking direct subordinate will similarly be promoted, and the promotions will cascade down the hierarchy until a person having no subordinates has been promoted. In Figure 1, if Tanenbaum gets fired, then Stallings will be promoted to Tanenbaum's position and seniority, and Knuth will be promoted to Stallings' previous position and seniority.

Figure 2 shows the hierarchy resulting from Figure 1 after (1) VonNeumann hires Shannon and (2) Tanenbaum gets fired:

Input

The first line of the input contains only the name of the person who is initially the CEO. All names in the input file consist of 2 to 20 characters, which may be upper or lower case letters, apostrophes, and hyphens. (In particular, no blank spaces.) Each name contains at least one upper case and at least one lower case letter.

The first line will be followed by one or more additional lines. The format of each of these lines will be determined by one of the following three rules of syntax:
[existing member] hires [new member]
fire [existing member]
print

Here [existing member] is the name of any individual who is already a member of the organization, [new member] is the name of an individual who is not a member of the organization as yet. The three types of lines (hires, fire, and print) can appear in any order, any number of times.

You may assume that at any time there is at least one member (who is the CEO) and no more than 1000 members in the organization.
Output

For each print command, print the current hierarchy of the organization, assuming all hires and fires since the beginning of the input have been processed as explained above. Tree diagrams (such as those in Figures 1 and 2) are translated into textual format according to the following rules:
Each line in the textual representation of the tree will contain exactly one name.
The first line will contain the CEO's name, starting in column 1.
The entire tree, or any sub-tree, having the form

will be represented in textual form as:

The output resulting from each print command in the input will be terminated by one line consisting of exactly 60 hyphens. There will not be any blank lines in the output.
Sample Input

VonNeumann
VonNeumann hires Tanenbaum
VonNeumann hires Dijkstra
Tanenbaum hires Stallings
Tanenbaum hires Silberschatz
Stallings hires Knuth
Stallings hires Hamming
Stallings hires Huffman
print
VonNeumann hires Shannon
fire Tanenbaum
print
fire Silberschatz
fire VonNeumann
print
Sample Output

VonNeumann
+Tanenbaum
++Stallings
+++Knuth
+++Hamming
+++Huffman
++Silberschatz

+Dijkstra

VonNeumann
+Stallings
++Knuth
+++Hamming
+++Huffman
++Silberschatz
+Dijkstra

+Shannon

Stallings
+Knuth
++Hamming
+++Huffman
+Dijkstra

+Shannon

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问

相似问题

2
C# MVC .net 根据条件检索后统计总金额
1
跪求大佬,请问怎么用代码实现求二叉排序树的平均检索长度,或者用什么思路实现
1
如何实现两个程序间的通信?
5
请教各位大拿,现在流行的网络爬虫有什么用
1
mysql 全文检索de和la搜不出结果
0
图像检索中相关反馈是怎么实现的?怎么手工打标记,标记后怎么检索的呢?急,在线等
1
c语言-想通过strstr函数检索关键词
0
怎么根据检索结果计算精准度(mAP,Top-N)呢?
1
C语言用二分查找的方式来检索字符串string,请问C语言的方式和思路
1
如何用VB实现ISBN网络检索
1
lucene检索结果,如何将分词后词语位置在一起的排最前面?
0
在图像检索中,ukbench和oxford buildings两个数据集的精准度是怎么计算的?
0
坐标的查找、检索和计算的问题,利用C语言的程序编写思路的实现的过程怎么做的?
1
关于Trie树的特点,一直都有一个疑问
0
C语言读文件然后进行检索的程序的设计,利用C语言代码编写思路的实现的方式怎么做?
1
python编程从入门到实践,13.4节,Alien检索不到Settings中的速度设置?
1
txt文件信息读不进去 c语言
2
怎么实现10000以内的回文数检索并输出
2
(C语言)在二叉搜索树的学习时遇到了问题,求大佬帮忙看看
0
根据条码编号查询的一种商品的名称,怎么用C语言的程序编写设计的思想原则来实现的代码编写