PAT
weixin_40343998
这个作者很懒,什么都没留下…
展开
-
1074 Reversing Linked List (25分)
前面是算法笔记的代码,比较繁琐,后两种是网上找的,放在这里日后对比学习一下。 #include<iostream> #include<algorithm> using namespace std; const int maxn = 100010; struct Node { //定义静态链表 int address; int data; int next; int order; }node[maxn]; bool cmp(Node a, Node b) { re原创 2020-05-30 16:23:46 · 124 阅读 · 0 评论 -
1051 Pop Sequence (25分)
Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, …, N and pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of the...原创 2020-02-24 12:07:23 · 83 阅读 · 0 评论 -
计算中缀表达式的值
输入:当一行中只有0 时输入结束,相应结果不输出。 分两步,一是将中缀转后缀,而是计算后缀表达式。 #include <iostream> #include <cstdio> #include <string> #include <stack> #include <queue> #include <map> using nam...原创 2020-02-24 11:17:21 · 240 阅读 · 0 评论 -
★★★1022 Digital Library (30分)
A Digital Library contains millions of books, stored according to their titles, authors, key words of their abstracts, publishers, and published years. Each book is assigned an unique 7-digit number a...原创 2020-02-23 20:44:33 · 84 阅读 · 0 评论 -
1071 Speech Patterns (25分)
People often have a preference among synonyms of the same word. For example, some may prefer “the police”, while others may prefer “the cops”. Analyzing such patterns can help to narrow down a speaker...原创 2020-02-23 16:45:41 · 63 阅读 · 0 评论 -
1054 The Dominant Color (20分)
Behind the scenes in the computer’s memory, color is always talked about as a series of 24 bits of information for each pixel. In an image, the color with the largest proportional area is called the d...原创 2020-02-23 15:58:21 · 53 阅读 · 0 评论 -
1100 Mars Numbers (20分)
People on Mars count their numbers with base 13: Zero on Earth is called “tret” on Mars. The numbers 1 to 12 on Earth is called “jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec” on Mars, re...原创 2020-02-23 14:09:48 · 55 阅读 · 0 评论 -
1060 Are They Equal (25分)
If a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 are considered equal since they are both saved as 0.123×10^5 with simple chopping. Now given the number of signifi...原创 2020-02-23 11:25:27 · 75 阅读 · 0 评论 -
1063 Set Similarity (25分)
Given two sets of integers, the similarity of the sets is defined to be Nc/Nt×100%, where Nc is the number of distinct common numbers shared by the two sets, and Nt is the total number of d...原创 2020-02-23 09:14:07 · 61 阅读 · 0 评论 -
1039 Course List for Student (25分) && 1047 Student List for Course (25分)
Input Specification: Each input file contains one test case. For each case, the first line contains 2 positive integers: N (≤40,000), the number of students who look for their course lists, and K (≤2,...原创 2020-02-22 22:23:59 · 106 阅读 · 0 评论 -
B1017 A除以B、A10231023 Have Fun with Numbers、1024 Palindromic Number以及高精度的四则运算
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; struct bign { int d[1000]; int len; bign() { //构造函数,用于初始化结构体 memset(d, 0, sizeof(d)); len = 0;...原创 2020-02-22 17:23:56 · 78 阅读 · 0 评论 -
1096 Consecutive Factors (20分)
Among all the factors of a positive integer N, there may exist several consecutive numbers. For example, 630 can be factored as 3×5×6×7, where 5, 6, and 7 are the three consecutive numbers. Now given ...原创 2020-02-22 14:42:52 · 64 阅读 · 0 评论 -
1059 Prime Factors (25分)
Input Specification: Each input file contains one test case which gives a positive integer N in the range of long int. Output Specification: Factor N in the format N = p1k1*p2k2*…*pm^k...原创 2020-02-22 12:02:15 · 91 阅读 · 0 评论 -
1078 Hashing (25分)
The 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%TSiz...原创 2020-02-22 09:47:11 · 73 阅读 · 0 评论 -
1015 Reversible Primes (20分)
A reversible prime in 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 pr...原创 2020-02-22 08:47:19 · 54 阅读 · 0 评论 -
1007 素数对猜想 (20分)
让我们定义dn为:dn=pn+1−pn,其中pi是第i个素数。显然有d1=1,且对于n>1有dn是偶数。“素数对猜想”认为“存在无穷多对相邻且差为2的素数”。 现给定任意正整数N(<10次方5),请计算不超过N的满足猜想的素数对的个数。 输入格式: 输入在一行给出正整数N。 输出格式: 在一行中输出不超过N的满足猜想的素数对的个数。 输入...原创 2020-02-21 22:20:08 · 48 阅读 · 0 评论 -
1034 有理数四则运算 (20分)
本题要求编写程序,计算 2 个有理数的和、差、积、商。 输入格式: 输入在一行中按照 a1/b1 a2/b2 的格式给出两个分数形式的有理数,其中分子和分母全是整型范围内的整数,负号只可能出现在分子前,分母不为 0。 输出格式: 分别在 4 行中按照 有理数1 运算符 有理数2 = 结果 的格式顺序输出 2 个有理数的和、差、积、商。注意输出的每个有理数必须是该有理数的最简形式 k a/b,其中 ...原创 2020-02-21 20:52:43 · 155 阅读 · 0 评论 -
1049 Counting Ones (30分)
The task is simple: given any positive integer N, you are supposed to count the total number of 1’s in the decimal form of the integers from 1 to N. For example, given N being 12, there are five 1’s i...原创 2020-02-21 15:47:03 · 61 阅读 · 0 评论 -
1049 数列的片段和 (20分)
给定一个正数数列,我们可以从中截取任意的连续的几个数,称为片段。例如,给定数列 { 0.1, 0.2, 0.3, 0.4 },我们有 (0.1) (0.1, 0.2) (0.1, 0.2, 0.3) (0.1, 0.2, 0.3, 0.4) (0.2) (0.2, 0.3) (0.2, 0.3, 0.4) (0.3) (0.3, 0.4) (0.4) 这 10 个片段。 给定正整数数列,求出全部片...原创 2020-02-21 14:27:11 · 80 阅读 · 0 评论 -
1019 数字黑洞 (20分)
给定任一个各位数字不完全相同的 4 位正整数,如果我们先把 4 个数字按非递增排序,再按非递减排序,然后用第 1 个数字减第 2 个数字,将得到一个新的数字。一直重复这样做,我们很快会停在有“数字黑洞”之称的 6174,这个神奇的数字也叫 Kaprekar 常数。 例如,我们从6767开始,将得到 7766 - 6677 = 1089 9810 - 0189 = 9621 9621 - 1269 ...原创 2020-02-21 13:02:25 · 81 阅读 · 0 评论 -
1003 我要通过! (20分)
“答案正确”是自动判题系统给出的最令人欢喜的回复。本题属于 PAT 的“答案正确”大派送 —— 只要读入的字符串满足下列条件,系统就输出“答案正确”,否则输出“答案错误”。 得到“答案正确”的条件是: 字符串中必须仅有 P、 A、 T这三种字符,不可以包含其它字符; 任意形如 xPATx 的字符串都可以获得“答案正确”,其中 x 或者是空字符串,或者是仅由字母 A 组成的字符串; 如果 aPbTc...原创 2020-02-21 12:11:10 · 50 阅读 · 0 评论 -
1045 快速排序 (25分)
著名的快速排序算法里有一个经典的划分过程:我们通常采用某种方法取一个元素作为主元,通过交换,把比主元小的元素放到它的左边,比主元大的元素放到它的右边。 给定划分后的 N 个互不相同的正整数的排列,请问有多少个元素可能是划分前选取的主元? 例如给定 N=5N = 5N=5, 排列是1、3、2、4、5。则: 1 的左边没有元素,右边的元素都比它大,所以它可能是主元; 尽管 3 的左边元素都比它小,但其...原创 2020-02-21 11:20:52 · 163 阅读 · 0 评论 -
1040 有几个PAT (25分)
字符串 APPAPT 中包含了两个单词 PAT,其中第一个 PAT 是第 2 位§,第 4 位(A),第 6 位(T);第二个 PAT 是第 3 位§,第 4 位(A),第 6 位(T)。 现给定字符串,问一共可以形成多少个 PAT? 输入格式: 输入只有一行,包含一个字符串,长度不超过10 5次方,只包含 P、A、T 三种字母。 输出格式: 在一行中输出给定字符串中包含多少个 PAT。由于...原创 2020-02-21 09:21:16 · 49 阅读 · 0 评论 -
1048 Find Coins (25分)
Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However,...原创 2020-02-19 16:57:51 · 108 阅读 · 0 评论 -
PAT B1013 数素数
1013 数素数 (20 分) 令 Pi 表示第 i 个素数。现任给两个正整数 M≤N≤104,请输出 PM 到 PN 的所有素数。 输入格式: 输入在一行中给出 M 和 N,其间以空格分隔。 输出格式: 输出从 PM 到 PN 的所有素数,每 10 个数字占 1 行,其间以空格分隔,但行末不得有多余空格。 输入样例: 5 27 输出样例: 11 13 17 1...原创 2019-01-21 11:30:38 · 82 阅读 · 0 评论