<> 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,
2020 The 11th National Blue Bridge Cup C/C++b Group summary ( Completion ) Review of the most complete computer network principles in history vue-cli 3 VUE Scaffold project construction ( Detailed explanation ) solve Vue+TypeScript Under development TS Don't recognize this.$refs The question of Vue Using the function of anti chattering and throttling How to use division operation in relational algebra SQL Statement representation ?copy-webpack-plugin Copy and compress files avue The use of dictionaries in English Teaching girls to learn Java: What is? Java?python Code painting Cherry Blossom -python Draw cherry tree code Specific code introduction