系列文章目录
备考PAT&考研2021.6.27
前言
pat乙级刷题训练&考研&计算机二级(7&8月)
争取每天5道题左右,一周5次以上。
AC就算成功(左手脸)。
编译器&语言:c++(c)&clang++
一、 部分A+B
1.题目
2.代码
#include <cstdio>
int main() {
long long A, B,a,b;
scanf("%lld %lld %lld %lld", &A, &a, &B, &b);
long long sumb = 0,suma = 0;
while (A != 0) {
if (A%10 == a) suma=suma*10+a;
A = A / 10;
}
while (B != 0) {
if (B%10==b) sumb=sumb*10+b;
B = B / 10;
}
printf("%lld\n", suma + sumb);
return 0;
}
二、一元多项
1.题目
设计函数求一元多项式的导数(利用指数求导公式)
2.代码
#include <cstdio>
int main() {
int a[1010] = { 0 };
int k, e, count = 0;
while (scanf("%d%d", &k, &e) != EOF) {
a[e] = k;
}
a[0] = { 0 };
for (int i = 1; i <= 1000; i++) {
a[i - 1] = a[i] * i;//求导公式
a[i] = 0;//这句不可以省略
if (a[i - 1] != 0) count++; //count计数不为0的导数个数
}
if (count == 0) printf("0 0");
else {
for (int i = 1000; i >= 0; i--) {
if (a[i] != 0) {
printf("%d %d", a[i], i);
count--;
if (count != 0) printf(" ");
}
}
}
return 0;
}
三、Shuffling Machine(第一个甲级题)
1.题目
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 automatic shuffling machines. Your task is to simulate a shuffling machine.
The machine shuffles a deck of 54 cards according to a given random order and repeats for a given number of times. It is assumed that the initial status of a card deck is in the following order:
Input Specification:
Each input file contains one test case. For each case, the first line contains a positive integer K (≤20) which is the number of repeat times. Then the next line contains the given order. All the numbers in a line are separated by a space.
Output Specification:
For each test case, print the shuffling results in one line. All the cards are separated by a space, and there must be no extra space at the end of the line.
2.代码
#include <cstdio>
const int N = 54;
char mp[5] = { 'S','H','C','D','J' };
int start[N + 1], end[N + 1], next[N + 1];
int main() {
int k;
scanf("%d", &k);
for (int i = 1; i <= N; i++) {
start[i] = i;
}
for (int i = 1; i <= N; i++) {
scanf("%d", &next[i]);
}
for (int step = 0; step < k; step++) {
for (int i = 1; i <=N; i++) {
end[next[i]] = start[i];
}
for(int i = 1; i <= N; i++) {
start[i] = end[i];
}
}
for (int i = 1; i <= N; i++) {
if (i != 1) printf(" ");
start[i]--;
printf("%c%d", mp[start[i] / 13], start[i] % 13 + 1);
}
}