PAT甲级C++题解
文章平均质量分 77
PAT (Advanced Level) Practice
C++题解
Shine_YP
这个作者很懒,什么都没留下…
展开
-
1046 Shortest Distance (20 分)
The task is really simple: givenNexits on a highway which forms a simple cycle, you are supposed to tell the shortest distance between any pair of exits.Input Specification:Each input file contains one test case. For each case, the first line contain..原创 2022-03-09 17:35:59 · 112 阅读 · 0 评论 -
1042 Shuffling Machine (20 分)
Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid "inside jobs" where employees collaborate with gamblers by performing inadequate shuffles, many casinos employ原创 2022-03-08 14:47:55 · 158 阅读 · 0 评论 -
1041 Be Unique (20 分)
Being unique is so important to people on Mars that even their lottery is designed in a unique way. The rule of winning is simple: one bets on a number chosen from [1,104]. The first one who bets on a unique number wins. For example, if there are 7 people原创 2022-03-07 12:08:10 · 120 阅读 · 0 评论 -
1035 Password (20 分)
To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distinguish1(one) froml(Lin lowercase), or0(zero) fromO(oin uppercase). One ...原创 2022-03-07 11:02:26 · 118 阅读 · 0 评论 -
1031 Hello World for U (20 分)
Given any string ofN(≥5) characters, you are asked to form the characters into the shape ofU. For example,helloworldcan be printed as:h de ll rlowoThat is, the characters must be printed in the original order, starting top-down from the le...原创 2022-02-24 09:08:07 · 335 阅读 · 0 评论 -
1027 Colors in Mars (20 分)
People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digits are forRed, the middle 2 digits forGreen, and the last 2 digits forBlue. The only ...原创 2022-02-24 08:49:42 · 306 阅读 · 0 评论 -
1023 Have Fun with Numbers (20 分)
Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number consisting exactly the numbers from 1 to 9, only in a diffe原创 2022-02-17 12:19:33 · 318 阅读 · 0 评论 -
1021 Deepest Root (25 分)
A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a highest tree. Such a root is calledthe deepest root.Input Specification:Each .原创 2022-02-17 00:27:14 · 162 阅读 · 0 评论 -
1020 Tree Traversals (25 分)
Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversal sequence of the corresponding binary tree.Input Specification:Each inpu原创 2022-02-16 12:12:56 · 288 阅读 · 0 评论 -
1019 General Palindromic Number (20 分)
A number that will be the same when it is written forwards or backwards is known as aPalindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers.Although palindromic numbers are most often considere.原创 2022-02-15 22:51:32 · 142 阅读 · 0 评论 -
1018 Public Bike Management (30 分)
There is a public bike service in Hangzhou City which provides great convenience to the tourists from all over the world. One may rent a bike at any station and return it to any other stations in the city.The Public Bike Management Center (PBMC) keeps mo原创 2022-02-15 14:58:35 · 453 阅读 · 0 评论 -
1017 Queueing at Bank (25 分)
Suppose a bank hasKwindows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. All the customers have to wait in line behind the yellow line, until it is his/her turn to be served and there is a..原创 2022-02-15 10:06:05 · 118 阅读 · 0 评论 -
1016 Phone Bills (25 分)
A long-distance telephone company charges its customers by the following rules:Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When a customer starts connecting a long-distance call, the原创 2022-02-14 22:18:59 · 178 阅读 · 0 评论 -
1010 Radix (25 分)
Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer isyes, if 6 is a decimal number and 110 is a binary number.Now for any pair of positive integersN1andN2, your task is to find the radix of one ...原创 2022-02-14 18:09:31 · 151 阅读 · 0 评论 -
1015 Reversible Primes (20 分)
Areversible primein any number system is a prime whose "reverse" in that number system is also a prime. For example in the decimal system 73 is a reversible prime because its reverse 37 is also a prime.Now given any two positive integersN(<105) an...原创 2022-02-14 16:58:04 · 282 阅读 · 0 评论 -
1014 Waiting in Line (30 分)
Suppose a bank hasNwindows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. The rules for the customers to wait in line are:The space inside the yellow line in front of each window is enoug..原创 2022-02-14 11:39:22 · 222 阅读 · 0 评论 -
1013 Battle Over Cities (25 分)
It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We must know immediately if we need to repair any other highways to keep the rest of the c原创 2022-02-12 22:34:58 · 159 阅读 · 0 评论 -
1012 The Best Rank (25 分)
To evaluate the performance of our first year CS majored students, we consider their grades of three courses only:C- C Programming Language,M- Mathematics (Calculus or Linear Algrbra), andE- English. At the mean time, we encourage students by emphasi...原创 2022-02-12 19:05:53 · 318 阅读 · 0 评论 -
1011 World Cup Betting (20 分)
With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing battles for the World Cup trophy in South Africa. Similarly, football betting fans were putting their money原创 2022-02-12 16:36:30 · 159 阅读 · 0 评论 -
1009 Product of Polynomials (25 分)
This time, you are supposed to findA×BwhereAandBare two polynomials.Input Specification:Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial:KN1aN1N2aN2...NKaNK...原创 2022-02-10 22:18:58 · 52 阅读 · 0 评论 -
1008 Elevator (20 分)
The highest building in our city has only one elevator. A request list is made up withNpositive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to..原创 2022-02-10 19:43:41 · 354 阅读 · 0 评论 -
1007 Maximum Subsequence Sum (25 分)
Given a sequence ofKintegers {N1,N2, ...,NK}. A continuous subsequence is defined to be {Ni,Ni+1, ...,Nj} where1≤i≤j≤K. The Maximum Subsequence is the continuous subsequence which has the largest sum of its elements. For example, given seq...原创 2022-02-10 19:15:06 · 591 阅读 · 0 评论 -
1006 Sign In and Sign Out (25 分)
At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing in's and out's, you are supposed to find the ones who have unlocked and loc原创 2022-02-10 17:01:14 · 162 阅读 · 0 评论 -
1005 Spell It Right (20 分)
Given a non-negative integerN, your task is to compute the sum of all the digits ofN, and output every digit of the sum in English.Input Specification:Each input file contains one test case. Each case occupies one line which contains anN(≤10100)....原创 2022-02-10 14:00:30 · 522 阅读 · 0 评论 -
1004 Counting Leaves (30 分)
A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child.Input Specification:Each input file contains one test case. Each case starts with a line containing0<N<100, the number of nod.原创 2022-02-10 13:12:41 · 98 阅读 · 0 评论 -
1003 Emergency (25 分)
As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of each road between any pair of cities are marked原创 2022-02-10 11:45:34 · 167 阅读 · 0 评论 -
1002 A+B for Polynomials (25 分)
This time, you are supposed to findA+BwhereAandBare two polynomials.Input Specification:Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial:KN1aN1N2aN2...NKaNK...原创 2022-02-09 22:35:35 · 168 阅读 · 0 评论 -
1001 A+B Format (20 分)
Calculate a+b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).Input Specification:Each input file contains one test case. Each case contains a pair o原创 2022-02-09 21:00:07 · 192 阅读 · 0 评论