
数据结构
中国大学MOOC_数据结构_PTA题目
王寒寒
苦练基本功,长期有耐心
展开
-
重要题目汇总
文章目录牛客牛客JZ17原创 2020-12-13 11:50:47 · 110 阅读 · 0 评论 -
KMP 串的模式匹配
KMP 串的模式匹配来自:PTA_数据结构_KMP 串的模式匹配给定两个由英文字母组成的字符串 String 和 Pattern,要求找到 Pattern 在 String 中第一次出现的位置,并将此位置后的 String 的子串输出。如果找不到,则输出“Not Found”。本题旨在测试各种不同的匹配算法在各种数据情况下的表现。各组测试数据特点如下:输入格式:输入第一行给出 String,为由英文字母组成的、长度不超过 10^6 的字符串。第二行给出一个正整数 N(≤10),为待匹配的模式串的原创 2020-05-24 16:04:36 · 666 阅读 · 0 评论 -
11-散列4 Hashing - Hard Version
11-散列4 Hashing - Hard Version来自:PTA_数据结构_Hashing - Hard VersionGiven a hash table of size N, we can define a hash function H(x)=x%N. Suppose that the linear probing is used to solve collisions, we can easily obtain the status of the hash table with a giv原创 2020-05-24 09:58:33 · 381 阅读 · 0 评论 -
11-散列3 QQ帐户的申请与登陆
11-散列3 QQ帐户的申请与登陆实现QQ新帐户申请和老帐户登陆的简化版功能。最大挑战是:据说现在的QQ号码已经有10位数了。输入格式:输入首先给出一个正整数N( ≤10^5 ),随后给出N行指令。每行指令的格式为:“命令符(空格)QQ号码(空格)密码”。其中命令符为“N”(代表New)时表示要新申请一个QQ号,后面是新帐户的号码和密码;命令符为“L”(代表Login)时表示是老帐户登陆,后面是登陆信息。QQ号码为一个不超过10位、但大于1000(据说QQ老总的号码是1001)的整数。密码为不小原创 2020-05-23 10:09:53 · 479 阅读 · 0 评论 -
11-散列2 Hashing
11-散列2 Hashing来自:PTA_数据结构_散列2 HashingThe task of this problem is simple: insert a sequence of distinct positive integers into a hash table, and output the positions of the input numbers. The hash function is defined to be H(key)=key%TSize where TSize is原创 2020-05-23 07:39:54 · 198 阅读 · 0 评论 -
10-排序6 Sort with Swap(0, i)
10-排序6 Sort with Swap(0, i)来自:PTA_数据结构_排序6 Sort with Swap(0, i)Given any permutation of the numbers {0, 1, 2,…, N−1}, it is easy to sort them in increasing order. But what if Swap(0, *) is the ONLY operation that is allowed to use? For example, to sort {原创 2020-05-22 20:09:06 · 197 阅读 · 0 评论 -
10-排序5 PAT Judge
10-排序5 PAT Judge来自:PTA_数据结构_排序5 PAT JudgeThe ranklist of PAT is generated from the status list, which shows the scores of the submissions. This time you are supposed to generate the ranklist for PAT.Input Specification:Each input file contains one test原创 2020-05-22 15:51:48 · 162 阅读 · 0 评论 -
10-排序4 统计工龄
10-排序4 统计工龄来自:PTA_数据结构_排序4 统计工龄给定公司N名员工的工龄,要求按工龄增序输出每个工龄段有多少员工。输入格式:输入首先给出正整数N(≤10^5),即员工总人数;随后给出N个整数,即每个员工的工龄,范围在[0, 50]。输出格式:按工龄的递增顺序输出每个工龄的员工个数,格式为:“工龄:人数”。每项占一行。如果人数为0则不输出该项。输入样例:810 2 0 5 7 2 5 2输出样例:0:12:35:27:110:1程序代码:#include <原创 2020-05-21 23:44:01 · 233 阅读 · 0 评论 -
09-排序3 Insertion or Heap Sort
09-排序3 Insertion or Heap Sort来自:PTA_数据结构_排序3 Insertion or Heap SortAccording to Wikipedia:Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the原创 2020-05-19 21:52:40 · 173 阅读 · 0 评论 -
09-排序2 Insert or Merge
09-排序2 Insert or Merge来自:PTA_数据结构_排序2 Insert or MergeAccording to Wikipedia:Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data, f原创 2020-05-19 18:50:01 · 177 阅读 · 0 评论 -
09-排序1 排序
09-排序1 排序来自:PTA_数据结构_排序1 排序给定N个(长整型范围内的)整数,要求输出从小到大排序后的结果。本题旨在测试各种不同的排序算法在各种数据情况下的表现。各组测试数据特点如下:数据1:只有1个元素;数据2:11个不相同的整数,测试基本正确性;数据3:10^3个随机整数;数据4:10^4个随机整数;数据5:10^5个随机整数;数据6:10^5个顺序整数;数据7:10^5个逆序整数;数据8:10^5个基本有序的整数;数据9:10^5个随机正整数,每个数字不超过1000。原创 2020-05-19 15:45:15 · 700 阅读 · 0 评论 -
07-图6 旅游规划
07-图6 旅游规划来自:PTA_数据结构_旅游规划有了一张自驾旅游路线图,你会知道城市间的高速公路长度、以及该公路要收取的过路费。现在需要你写一个程序,帮助前来咨询的游客找一条出发地和目的地之间的最短路径。如果有若干条路径都是最短的,那么需要输出最便宜的一条路径。输入格式:输入说明:输入数据的第1行给出4个正整数N、M、S、D,其中N(2≤N≤500)是城市的个数,顺便假设城市的编号为0~(N−1);M是高速公路的条数;S是出发地的城市编号;D是目的地的城市编号。随后的M行中,每行给出一条高速公路原创 2020-05-18 13:03:36 · 276 阅读 · 0 评论 -
07-图5 Saving James Bond - Hard Version
07-图5 Saving James Bond - Hard Version来自:PTA_数据结构_Saving James Bond - Hard VersionThis time let us consider the situation in the movie “Live and Let Die” in which James Bond, the world’s most famous spy, was captured by a group of drug dealers. He was se原创 2020-05-17 23:35:47 · 259 阅读 · 0 评论 -
07-图4 哈利·波特的考试
07-图4 哈利·波特的考试来自:PTA_数据结构_哈利·波特的考试哈利·波特要考试了,他需要你的帮助。这门课学的是用魔咒将一种动物变成另一种动物的本事。例如将猫变成老鼠的魔咒是haha,将老鼠变成鱼的魔咒是hehe等等。反方向变化的魔咒就是简单地将原来的魔咒倒过来念,例如ahah可以将老鼠变成猫。另外,如果想把猫变成鱼,可以通过念一个直接魔咒lalala,也可以将猫变老鼠、老鼠变鱼的魔咒连起来念:hahahehe。现在哈利·波特的手里有一本教材,里面列出了所有的变形魔咒和能变的动物。老师允许他自己带原创 2020-05-17 21:52:41 · 122 阅读 · 0 评论 -
06-图1 列出连通集
06-图1 列出连通集来自:PTA_数据结构_列出连通集给定一个有N个顶点和E条边的无向图,请用DFS和BFS分别列出其所有的连通集。假设顶点从0到N−1编号。进行搜索时,假设我们总是从编号最小的顶点出发,按编号递增的顺序访问邻接点。输入格式:输入第1行给出2个整数N(0<N≤10)和E,分别是图的顶点数和边数。随后E行,每行给出一条边的两个端点。每行中的数字之间用1空格分隔。输出格式:按照"{ v1 v2 … vk}"的格式,每行输出一个连通集。先输出DFS的结果,再输出BFS的结果原创 2020-05-17 13:09:24 · 480 阅读 · 0 评论 -
05-树8 File Transfer
05-树8 File Transfer来自:PTA_数据结构_File TransferWe have a network of computers and a list of bi-directional connections. Each of these connections allows a file transfer from one computer to another. Is it possible to send a file from any computer on the net原创 2020-05-16 16:47:18 · 181 阅读 · 0 评论 -
05-树7 堆中的路径
05-树7 堆中的路径来自:PTA_数据结构_堆中的路径将一系列给定数字插入一个初始为空的小顶堆H[ ]。随后对任意给定的下标i,打印从H[i]到根结点的路径。输入格式:每组测试第1行包含2个正整数N和M(≤1000),分别是插入元素的个数、以及需要打印的路径条数。下一行给出区间[-10000, 10000]内的N个要被插入一个初始为空的小顶堆的整数。最后一行给出M个下标。输出格式:对输入中给出的每个下标i,在一行中输出从H[i]到根结点的路径上的数据。数字间以1个空格分隔,行末不得有多余空格。原创 2020-05-16 11:08:04 · 253 阅读 · 0 评论 -
04-树7 二叉搜索树的操作集
04-树7 二叉搜索树的操作集来自:PTA_数据结构_二叉搜索树的操作集本题要求实现给定二叉搜索树的5种常用操作。函数接口定义:BinTree Insert( BinTree BST, ElementType X );BinTree Delete( BinTree BST, ElementType X );Position Find( BinTree BST, ElementType X );Position FindMin( BinTree BST );Position FindMax(原创 2020-05-10 23:39:55 · 172 阅读 · 0 评论