UVA-11995 - I Can Guess the Data Structure!

  • UVa Online Judge 解題結果請於 Submit 後,參閱 uHunt
  • 如果你有任何建議與指教,歡迎於下方留言一起討論喔!
  • 本題選為「20160524 大學程式能力檢定 CPE」題目。

題意概要

題目有個像袋子一樣的資料結構,並提供兩種操作:

操作 操作描述
1 把 x 這個元素丟進袋子裡
2 從袋子裡拿出一個元素

現在給你一連串的序列,包含上述的兩種操作與回傳值,請猜出袋子是何種資料結構。有可能是堆疊 (Stack) [後進先出] 或 佇列 (Queue) [先進先出] 或優先權佇列 (Priority Queue) [每次拿出較大的元素],也有可能是其他你沒有想到的東西。


Input

There are several test cases. Each test case begins with a line containing a single integer (). Each of the next lines is either a type-1 command, or an integer 2 followed by an integer . That means after executing a type-2 command, we get an element without error. The value of is always a positive integer not larger than 100. The input is terminated by end-of-file (EOF).


Output

For each test case, output one of the following:

Data structure Description
stack It’s definitely a stack.
queue It’s definitely a queue.
priority queue It’s definitely a priority queue.
impossible It can’t be a stack, a queue or a priority queue.
not sure It can be more than one of the three data structures mentioned above.

Sample Input

6
1 1
1 2
1 3
2 1
2 2
2 3
6
1 1
1 2
1 3
2 3
2 2
2 1
2
1 1
2 2
4
1 2
1 1
2 1
2 2
7
1 2
1 5
1 1
1 3
2 5
1 4
2 4

Sample Output

queue
not sure
impossible
stack
priority queue
profile-image
David Lu
Hello, I'm David Lu. I am a graduate student in Department of Computer Science at National Chiao Tung University, Taiwan. I am in the Networking and Sensing Systems (NSS) Lab at NCTU. If you have any question, please feel free to contact with me.
comments powered by Disqus