UEFU/
// PAT
1001 A+B Format (20分)


题目要求:
计算A+B的和,以每三位一个”,”的格式输出。
用s数组记录每3位的数字,然后按照格式输出。
先输出最高位的数值也就是s[–e],然后是,s[e–]即可。
因为之前的循环e多1要先减1再用,之后都是先判断再减1再用。
1 |
|
1002 A+B for Polynomials


相同次数的系数合并,统计系数不为0的项,输出。
a[exp] += num; 比如a[2]也就是x的平方的系数。exp = 0也就是常数项。
因为没有说同一行输入不会出现相同次数的项,因此要+=,当然+=也能很好地处理系数不同的问题。
求8x²-7x+5与3x²-4x+1的差。
解: (8x²-7x+5)-(3x²-4x+1)
=8x²-7x+5-3x²+4x-1
=5x²-3x+41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using namespace std;
int main() {
int k1, k2, exp;
float num;
float a[1001] = {0};
scanf("%d", &k1);
for (int i = 0; i < k1; i++) {
scanf("%d%f", &exp, &num);
a[exp] += num;
}
scanf("%d", &k2);
for (int i = 0; i < k2; i++) {
scanf("%d%f", &exp, &num);
a[exp] += num;
}
int cnt = 0;
for (int i = 0; i < 1001; i++) {
if (a[i] != 0) cnt++;
}
printf("%d", cnt);
for (int i = 1000; i >= 0; i--) {
if (a[i] != 0) {
printf(" %d %.1f", i, a[i]);
}
}
return 0;
}
2 1 2.4 0 3.2
2 2 1.5 1 0.5
3 2 1.5 1 2.9 0 3.2
1003 Emergency (25 分)


1 |
|
1004 Counting Leaves
1 |
1006 Sign In and Sign Out (25 分)
1 |
1005 Spell It Right


题目大意:
输入一个数字,把数字的每一位相加,用英文输出最后总和的每一位数字。
因为输入的数字可能很大,所以用字符串的形式输入。即使每一位是9,和也不过是900罢了。
之后转换为字符串,输出每一位的数字。
1 |
|
1006 Sign In and Sign Out


题目大意:
告诉你M个工作人员的出入记录,最早进门的人负责开门,最晚出门的负责关门。
请问,谁开的门和谁关的门。
总体思想是把所有人的进出时间统一到一个可以比较的刻度上,比如,进出时间是当天的第几秒。
之后用2个临时变量保存当前着的进出时间和最早和最晚比,更新最早和最晚时间。
输出最后结果。
1 |
|
1007 Maximum Subsequence Sum
题目大意:
输出最大子序列和,以及首尾元素。
1 |
|
1009 Product of Polynomials (25 分)
题目大意:
求2个多项式A*B后的结果。
1 |
|
❌ 1010 Radix (25 分)
1 |
|
1011 World Cup Betting (20)
1 |
|
❌ 1012 The Best Rank (25 分)
1 |
|
1013 Battle Over Cities (25 分)
1 |
1015 Reversible Primes (20 分)
1 |
|
1016 Phone Bills (25 分) UN
1 |
|
❌ 1017 Queueing at Bank (25 分)
1 |
|
1019 General Palindromic Number (20 分)
1 |
|
1020 Tree Traversals (25 分)
1 |
|
1 |
|
❌ 1021 Deepest Root (25 分)
1 |
|
1023 Have Fun with Numbers (20 分)
1 |
|
1025 PAT Ranking (25 分)
1 |
|
题目要求:The locations are numbered from 1 to N. The output must be sorted in nondecreasing order of the final ranks. The testees with the same score must have the same rank, and the output must be sorted in nondecreasing order of their registration numbers.
也就是说,学生的排名和学号都是非递减。那么排名优先是按照分数高在前,低在后。
因此用return a.score != b.score ? a.score > b.score : a.no < b.no;也就说,分数不同时,分数高优先,分数相同时,学号小优先。
1027 Colors in Mars (20 分)
1 |
|
1028 List Sorting (25 分)
1 |
|
1029 Median (25 分)
1 |
|
1031 Hello World for U (20 分)
1 |
|
1032 Sharing (25 分)
1 |
|
❌ 1033 To Fill or Not to Fill (25 分)
1 |
|
1035 Password (20 分)
1 |
|
# 1036 Boys vs Girls (25 分)1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using namespace std;
int main() {
int n;
scanf("%d", &n);
string female, male;
int femalescore = -1, malescore = 101;
for (int i = 1; i <= n; i++) {
string name, sex, num;
int score;
cin >> name >> sex >> num;
scanf("%d", &score);
if (sex == "F") {
if (femalescore < score) {
femalescore = score;
female = name + " " + num;
}
} else if (malescore > score) {
malescore = score;
male = name + " " + num;
}
}
if (femalescore != -1) {
cout << female << endl;
} else {
printf("Absent\n");
}
if (malescore != 101) {
cout << male << endl;
} else {
printf("Absent\n");
}
if (femalescore != -1 && malescore != 101) {
printf("%d", femalescore - malescore);
} else {
printf("NA");
}
return 0;
}
3
Joe M Math990112 89
Mike M CS991301 100
Mary F EE990830 95
Mary EE990830
Joe Math990112
6
1037 Magic Coupon (25 分)
1 |
|
1039 Course List for Student (25 分)
1 |
|
❌⭕ 1040 Longest Symmetric String (25 分) 对递推方程还是有疑虑
1 |
|
1041 Be Unique (20 分)
1 |
|
1042 Shuffling Machine (20 分)
1 |
|
❌ 1043 Is It a Binary Search Tree (25 分)
1 |
|
1044 Shopping in Mars (25 分)
1 |
|
1046 Shortest Distance (20 分)
1 |
|
1048 Find Coins (25 分)
1 |
1050 String Subtraction (20 分)
1 |
|
1051 Pop Sequence (25 分)
1 |
|
1054 The Dominant Color (20 分)
1 |
|
1055 The World’s Richest (25 分)
1 |
|
1056 Mice and Rice (25 分)
1 |
|
1058 A+B in Hogwarts (20 分)
1 |
|
1059 Prime Factors (25 分)
1 |
|
输出十万内的素数。1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using namespace std;
vector<int> prime(100000, 1);
int main() {
// freopen("1.txt", "r", stdin);
freopen("out.txt","w",stdout);
for (int i = 2; i * i < 100000; i++) {
for (int j = 2; j * i < 100000; j++) {
prime[i * j] = 0;
}
}
printf("2");
for (int i = 3; i < 100000; i++) {
if (prime[i]) printf(" %d", i);
}
return 0;
}
5万以后的素质:
49939 49943 49957 49991 49993 49999 50021 50023 50033 50047 50051 50053 50069 50077 50087 50093 50101 50111 50119 50123 50129 50131 50147 50153 50159 50177 50207 50221 50227 50231 50261 50263 50273 50287 50291 50311 50321 50329 50333 50341 50359 50363 50377 50383 50387 50411 50417 50423 50441 50459 50461 50497 50503 50513 50527 50539 50543 50549 50551 50581 50587 50591 50593 50599 50627 50647 50651 50671 50683 50707 50723 50741 50753 50767 50773 50777 50789 50821 50833 50839 50849 50857 50867 50873 50891 50893 50909 50923 50929 50951 50957 50969 50971 50989 50993 51001 51031 51043 51047 51059 51061 51071 51109 51131 51133 51137 51151 51157 51169 51193 51197 51199 51203 51217 51229 51239 51241 51257 51263 51283 51287 51307 51329 51341 51343 51347 51349 51361 51383 51407 51413 51419 51421 51427 51431 51437 51439 51449 51461 51473 51479 51481 51487 51503 51511 51517 51521 51539 51551 51563 51577 51581 51593
sqrt(1.0 * INT32_MAX)的值。1
2
3
4
5
6
7
8
9
10
11
12
using namespace std;
int main() {
int res = sqrt(1.0 * INT32_MAX);
printf("%d", res);
return 0;
}
46340
会出现重复情况吗?会的。1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using namespace std;
vector<int> prime(100000, 1);
int main() {
// freopen("1.txt", "r", stdin);
freopen("out.txt","w",stdout);
int cnt = 0;
for (int i = 2; i * i < 100; i++) {
for (int j = 2; j * i < 100; j++) {
prime[i * j] = 0;
printf("%2d %2d %3d ", i, j, i * j);
cnt++;
if (cnt % 5 == 0) printf("\n");
}
}
printf("\n");
printf("cnt = %d\n\n", cnt);
printf("2");
for (int i = 3; i < 100; i++) {
if (prime[i]) printf(" %d", i);
}
return 0;
}
2 2 4 2 3 6 2 4 8 2 5 10 2 6 12
2 7 14 2 8 16 2 9 18 2 10 20 2 11 22
2 12 24 2 13 26 2 14 28 2 15 30 2 16 32
2 17 34 2 18 36 2 19 38 2 20 40 2 21 42
2 22 44 2 23 46 2 24 48 2 25 50 2 26 52
2 27 54 2 28 56 2 29 58 2 30 60 2 31 62
2 32 64 2 33 66 2 34 68 2 35 70 2 36 72
2 37 74 2 38 76 2 39 78 2 40 80 2 41 82
2 42 84 2 43 86 2 44 88 2 45 90 2 46 92
2 47 94 2 48 96 2 49 98 3 2 6 3 3 9
3 4 12 3 5 15 3 6 18 3 7 21 3 8 24
3 9 27 3 10 30 3 11 33 3 12 36 3 13 39
3 14 42 3 15 45 3 16 48 3 17 51 3 18 54
3 19 57 3 20 60 3 21 63 3 22 66 3 23 69
3 24 72 3 25 75 3 26 78 3 27 81 3 28 84
3 29 87 3 30 90 3 31 93 3 32 96 3 33 99
4 2 8 4 3 12 4 4 16 4 5 20 4 6 24
4 7 28 4 8 32 4 9 36 4 10 40 4 11 44
4 12 48 4 13 52 4 14 56 4 15 60 4 16 64
4 17 68 4 18 72 4 19 76 4 20 80 4 21 84
4 22 88 4 23 92 4 24 96 5 2 10 5 3 15
5 4 20 5 5 25 5 6 30 5 7 35 5 8 40
5 9 45 5 10 50 5 11 55 5 12 60 5 13 65
5 14 70 5 15 75 5 16 80 5 17 85 5 18 90
5 19 95 6 2 12 6 3 18 6 4 24 6 5 30
6 6 36 6 7 42 6 8 48 6 9 54 6 10 60
6 11 66 6 12 72 6 13 78 6 14 84 6 15 90
6 16 96 7 2 14 7 3 21 7 4 28 7 5 35
7 6 42 7 7 49 7 8 56 7 9 63 7 10 70
7 11 77 7 12 84 7 13 91 7 14 98 8 2 16
8 3 24 8 4 32 8 5 40 8 6 48 8 7 56
8 8 64 8 9 72 8 10 80 8 11 88 8 12 96
9 2 18 9 3 27 9 4 36 9 5 45 9 6 54
9 7 63 9 8 72 9 9 81 9 10 90 9 11 99
cnt = 170
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
PS:
打印素数的几种方法及其优化
https://blog.csdn.net/aixiaodeshushu/article/details/81429285
1060 Are They Equal (25 分)
1 |
1061 Dating (20 分)
1 |
|
1065 A+B and C (64bit) (20 分)
1 |
|
1069 The Black Hole of Numbers
1 |
|
1073 Scientific Notation (20 分)
1 |
|
1077 Kuchiguse (20 分)
1 |
|
1078 Hashing (25 分)
1 |
1081 Rational Sum (20 分)
1 |
|
1084 Broken Keyboard (20 分)
1 |
|
1088 Rational Arithmetic (20 分) !!!
1 |
|
1092 To Buy or Not to Buy (20 分)
1 |
|
1096 Consecutive Factors (20 分)
1 |
|
1100 Mars Numbers (20 分)
1 |
|
1104 Sum of Number Segments (20 分)
1 |
|
1108 Finding Average (20 分)
1 |
|