原创 PAT (Advanced Level) 1071. Speech Patterns (25) 字符串處理

People often have a preference among synonyms of the same word. For example, some may prefer "the police", while other

原创 PAT (Advanced Level) 1089. Insert or Merge (25) 插入和歸併

According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and growing a sorted ou

原创 PAT (Advanced Level) 1076. Forwards on Weibo (30) 微博轉發 BFS

Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may follow many other

原创 PAT (Advanced Level) 1090. Highest Price in Supply Chain (25) 供應鏈,BFS

A supply chain is a network of retailers(零售商), distributors(經銷商), and suppliers(供應商)-- everyone involved in moving a p

原创 PAT (Advanced Level) 1087. All Roads Lead to Rome (30) 條條大路通羅馬 Dijkstra+DFS

Indeed there are many different tourist routes from our city to Rome. You are supposed to find your clients the route

原创 PAT (Advanced Level) 1086. Tree Traversals Again (25) 根據先根遍歷數組創建樹

An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that wh

原创 目錄樹的建立和輸出

在ZIP歸檔文件中,保留着所有壓縮文件和目錄的相對路徑和名稱。當使用WinZIP等GUI軟件打開ZIP歸檔文件時,可以從這些信息中重建目錄的樹狀結構。請編寫程序實現目錄的樹狀結構的重建工作。 輸入格式說明: 輸入首先給出正整數N(<

原创 Maximum Gap 尋找數組中排序後相鄰兩個數的最大差值,桶排序,O(n)

Given an unsorted array, find the maximum difference between the successive elements in its sorted form. Try to solve

原创 PAT (Advanced Level) 1097. Deduplication on a Linked List (25) 鏈表去重

Given a singly linked list L with integer keys, you are supposed to remove the nodes with duplicated absolute values o

原创 PAT (Advanced Level) 1095. Cars on Campus (30) 結構體排序,合併區間

Zhejiang University has 6 campuses and a lot of gates. From each gate we can collect the in/out times and the plate nu

原创 Word Break II 字符串分割 動態規劃+DFS

Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid di

原创 撲克牌算24點 DFS

一副撲克牌的每張牌表示一個數(J、Q、K分別表示11、12、13,兩個司令都表示6)。任取4張牌,即得到4個1~13的數,請添加運算符(規定爲加+ 減- 乘* 除/ 四種)使之成爲一個運算式。每個數只能參與一次運算,4個數順序可以任意組

原创 PAT (Advanced Level) 1099. Build A Binary Search Tree (30) 中序遍歷往BST中填數據

A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtr

原创 PAT (Advanced Level) 1096. Consecutive Factors (20) 連續質因數

Among all the factors of a positive integer N, there may exist several consecutive numbers. For example, 630 can be fa

原创 PAT (Advanced Level) 1094. The Largest Generation (25) 人數最多的一代,BFS

A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same ge