<> Title Description

Read in task scheduling sequence , output n A scheduling method suitable for one task .

<> input

The input contains multiple sets of test data .

Enter an integer on the first line of each group n(n<100000), It means yes n Tasks .

next n that 's ok , The first one in each line represents the antecedent task , The tasks in brackets are sequential tasks , Indicates that only when the antecedent task is completed , The next task can start . If the following order is NULL There is no subsequent task .

<> output

Output scheduling mode , Output if there are a variety of suitable scheduling methods , Please output the one with the smallest dictionary order .

<> sample input
4 Task0(Task1,Task2) Task1(Task3) Task2(NULL) Task3(NULL)
<> sample output
Task0 Task1 Task2 Task3
thinking : Use priority queue , You can use a structure to store tasks , use x To define the priority size , The smaller the priority ( First input priority ).
After each line of string is entered , Get the word of the task from the string , After obtaining, hash the word into the hash table , The next time it appears, it will not be dealt with , The specific code is as follows :
#include <map> #include <cstdio> #include <iostream> #include <queue> #include
<string> #include <cctype> using namespace std; struct task{ // Task structure string s;
// Task name int x; // Priority of tasks friend bool operator < (task a,task b){ if(a.s!=b.s)
return a.x>b.x; // If the task name is different , be x Small priority else return a.s>b.s; // Otherwise, according to the lexicographic order, the smaller one has priority } }t; int
main() { map<string,bool> hashTable; // Hashtable , Used to determine if the task has ever occurred priority_queue<task> q;
// Priority queue , Used to store tasks string s,word; //s Is a string per line ,word Used to get tasks int n,i,j,k; while(scanf(
"%d\n",&n)!=EOF){ k=0; // Set priority to 0( Small priority ) for(i=0;i<n;i++){ getline(cin,s); for(j=0
;j<s.length();j++){ // Get the word of the task if(isalnum(s[j])) // The task consists of letters and numbers , If the conditions are met , Then put it in word in
word.push_back(s[j]); else // Unqualified , For example, in the case of "(" Empty the words when you wait word.clear(); if(!word.empty(
)&&!isalnum(s[j+1])){ Indicates that the complete word has been obtained if(word=="NULL") // If it is NULL Then skip continue; if(
hashTable[word]==false){ // The mission didn't show up , Then proceed with the operation hashTable[word]=true;
// Place true, Don't do it the next time you encounter it t.s=word; t.x=k++; q.push(t); // Team the task structure } else continue; } }
} // Output process cout <<q.top().s; q.pop(); while(!q.empty()){ cout <<" "<<q.top().s; q.
pop(); } cout <<endl; } return 0; }

Technology
©2019-2020 Toolsou All rights reserved,
Hikvision - Embedded software written test questions C Language application 0 The length of array in memory and structure is 0 In depth analysis data structure --- The preorder of binary tree , Middle order , Subsequent traversal How to do it ipad Transfer of medium and super large files to computer elementui Shuttle box el-transfer Display list content text too long 2019 The 10th Blue Bridge Cup C/C++ A Summary after the National Games ( Beijing Tourism summary )unity Shooting games , Implementation of first person camera python of numpy Module detailed explanation and application case Study notes 【STM32】 Digital steering gear Horizontal and vertical linkage pan tilt Vue Used in Element Open for the first time el-dialog Solution for not getting element