It's not easy to make. Please praise me. I'm Wang Rui. Nice to meet you!

## 41. Eliminate singles (20 points)

L1-046 divide singles (20 points)

The so-called "Bachelor" here does not mean single. Wang La ~ refers to the numbers composed of 1, such as 1, 11, 111, 1111, etc. It is said that any single can be divided by an odd number that does not end with 5. For example, 111111 can be divided by 13. Now, your program will read in an integer x, which must be odd and not end with 5. Then, after calculation, two numbers are output: the first number s, which means that x multiplied by s is a bachelor, and the second number n is the number of digits of the bachelor. Of course, such a solution is not unique. The problem requires you to output the smallest solution.

Tip: an obvious way is to gradually increase the number of singles until you can divide x. But the difficulty is that s may be a very large number - for example, if the program inputs 31, it outputs 3584229390681 and 15, because the result of multiplying 31 by 3584229390681 is 111111111, a total of 15 1s.

Input format:

Input gives a positive odd number x (< 1000) that does not end with 5 in one line.

Output format:

Output the corresponding minimum s and n in one line, separated by 1 space.

Input example:

31

Output example:

3584229390681 15

#include<stdio.h> int main () { int n, len=0,p=0,now=1; char ans[1000]; scanf("%d",&n); while (!0) { len++; //1,11,111,111.... Try to divide if(p||now/n) //When the first bit of quotient is 0, it will not be output. p==0 ensures that the first bit is not output. More than the first bit will not output 0 ans[p++]='0'+now/n; //Savers, converting to characters now%=n; //Taking remainder is one of the keys of analog division if(now==0) { //The remainder is 0, which means it can be divided ans[p]='\0'; //The string created by yourself step by step should be added with the string terminator printf("%s %d\n", ans, len); break; } now=now*10+1; //Multiplying by 10 is the key to analog division } return 0; }

## 42. Pretend to sleep (10 points)

L1-047 sleeping (10 points)

You can never wake up a person who pretends to sleep - but by analyzing a person's breathing rate and pulse, you can find out who is pretending to sleep! The doctor told us that the breathing rate of normal people during sleep is 15-20 times per minute and the pulse is 50-70 times per minute. Given the respiratory rate and pulse of a series of people below, please find out who may be pretending to sleep among them, that is, those whose at least one index is not within the normal range.

Input format:

Input: in the first line, a positive integer n (≤ 10) is given. In the next N lines, each line gives a person's name (only a string composed of English letters and no more than 3 characters in length), his respiratory rate and pulse (both positive integers no more than 100).

Output format:

Check everyone according to the input order. If at least one of their indicators is not within the normal range, output their name, and each name occupies one line.

Input example:

4

Amy 15 70

Tom 14 60

Joe 18 50

Zoe 21 71

Output example:

Tom

Zoe

#include<stdio.h> int main(void) { int N; //Enter a positive integer scanf("%d",&N); char name[8][4]; //Name / / be sure to set one more character here int huxi[8]; //Respiratory rate int maibo[8]; //pulse int i; //Used for loops and array subscripts for(i=0;i<N;i++) //Provide input function scanf("%s%d%d",&name[i][0],&huxi[i],&maibo[i]); for(i=0;i<N;i++) if(huxi[i]<15 || huxi[i]>20 || maibo[i]<50 || maibo[i]>70) puts(name[i]); }

## 43. Matrix A multiplied by B (15 points)

L1-048 matrix A multiplied by B (15 points)

Given two matrices A and B, you are required to calculate their product matrix AB. It should be noted that only matrices with scale matching can be multiplied. That is, if a has R

a

Line, C

a

Column B has R

b

Line, C

b

Column, then only C

a

And R

b

When they are equal, the two matrices can be multiplied.

Input format:

The input gives two matrices A and B successively. For each matrix, first give its row number R and column number C in one row, then give C integers in each row of row R, separated by 1 space, and there are no redundant spaces at the beginning and end of the row. The input ensures that R and C of both matrices are positive numbers, and the absolute value of all integers does not exceed 100.

Output format:

If the scales of the two input matrices match, the product matrix AB is output according to the input format; otherwise, error: Ca is output= RB, where Ca is the number of columns of A and Rb is the number of rows of B.

Input example 1:

2 3

1 2 3

4 5 6

3 4

7 8 9 0

-1 -2 -3 -4

5 6 7 8

Output example 1:

2 4

20 22 24 16

53 58 63 28

Input example 2:

3 2

38 26

43 -5

0 17

3 2

-11 57

99 68

81 72

Output example 2:

Error: 2 != 3

#include<stdio.h> #define N 100 #define M 100 int main() { int a[N][M]={0},b[N][M]={0},c[N][M]={0}; int i,j,k; //Used for loops and array subscripts int ra,ca,rb,cb,rc,cc; //They represent rows and columns of rectangle A, rows and columns of rectangle B, and rows and columns of rectangle C, respectively int n; // scanf("%d %d",&ra,&ca); for(i=0;i<ra;i++) //Rectangle A for(j=0;j<ca;j++) scanf("%d",&a[i][j]); scanf("%d %d",&rb,&cb); for(i=0;i<rb;i++) //Rectangle B for(j=0;j<cb;j++) scanf("%d",&b[i][j]); if(ca == rb) { //Note that since we are going to multiply two rectangles, it is certain that these two rectangles are different in appearance, //When the same condition is judged by us, the other two conditions will determine the row and column criteria of rectangle C, so //Here, we should combine the rows of rectangle A and the columns of rectangle B as the shape of rectangle C, so as to participate in the calculation rc = ra; //Here, the row of rectangle A is taken as the row of rectangle C cc = cb; //Here, the column of rectangle B is taken as the column of rectangle C n = ca; //Here are the factors that determine the k cycle printf("%d %d\n",rc,cc); for(i=0;i<rc;i++) //Number of control rows { for(j=0;j<cc;j++) //Number of control columns { for(k=0;k<n;k++) //Find the elements in the first row of rectangle A, multiply them by the elements in the first column of rectangle b, and calculate the sum output { //and so on c[i][j]+=a[i][k]*b[k][j]; } if(j!=cc-1) printf("%d ",c[i][j]); else printf("%d",c[i][j]); } printf("\n"); //Wrap every time a column of data of rectangle C is output } } else //Output this message when the data exactly matches printf("Error: %d != %d\n",ca,rb); return 0; }

## 44. Penultimate string (15 points)

L1-050 penultimate string (15 points)

Given a string equal difference increment sequence composed entirely of lowercase English letters, the length of each string in the sequence is fixed as l, starting from L A and increasing in steps of 1. For example, when l is 3, the sequence is {AAA, AAB, AAA,..., aaz, aba, abb,..., abz,..., zzz}. The penultimate string in this sequence is zyz. For any given L, this question requires you to give the penultimate string of the corresponding sequence.

Input format:

Input gives two positive integers L (2 ≤ L ≤ 6) and N (≤ 10) in one line

5

).

Output format:

Output the penultimate string of the corresponding sequence in one line. The title guarantees that this string exists.

Input example:

3 7417

Output example:

pat

#include<stdio.h> #include<math.h> #define L 6 int main() { char ch[26]={'z','y','x','w','v','u','t','s','r','q','p','o','n','m' ,'l','k','j','i','h','g','f','e','d','c','b','a'}; char arr[L]; int n,l,a,i; //l is the length of the sequence, n is the position of the sequence in reverse order, and a is the position of a character of the string in the ch array scanf("%d %d",&l,&n); n=n-1; //According to the derivation process, it is found that the last character is correct after subtracting 1 for(i=0;i<l;i++) { a=n/pow(26,l-i-1); arr[i]=ch[a]; n=n-a*pow(26,l-i-1); } for(i=0;i<l;i++) { printf("%c",arr[i]); } return 0; }

## 45. Discount (5 points)

L1-051 discount (5 points)

When shopping for discounted goods in shopping malls, it takes a lot of brains to calculate the price after the discount. For example, if the original price is ￥ 988 and it is marked with a 70% discount, the discount price should be ￥ 988 x 70% = ￥ 691.60. Please write a program to calculate the discount price for customers.

Input format:

Enter the original price (a positive integer not exceeding 10000 yuan) and discount (an integer in the [1,9] range) of the goods given in one line, separated by spaces.

Output format:

The discount price of goods is output in one line, with 2 decimal places reserved.

Input example:

988 7

Output example:

691.60

#include<stdio.h> int main(void) { double before_money; //original price double after_money; //After discount double zhe; //discount scanf("%lf %lf",&before_money,&zhe); after_money=before_money*zhe/10; printf("%.2lf\n",after_money); }

## 46. We want to win in 2018 (5 points)

L1-052 2018 we want to win (5 points)

The registration invitation code of 2018 TIANTI competition is "2018wmyy", which means "we want to win in 2018". Please output this sentence in Chinese pinyin.

Input format:

No input for this question.

Output format:

Output in the first line: "2018"; Output in the second line: "Wo Men Yao Ying!".

Input example:

nothing

Output example:

2018

wo3 men2 yao4 ying2 !

#include<stdio.h> int main(void) { printf("2018\n"); printf("wo3 men2 yao4 ying2 !\n"); return 0; }

## 47. Electronic test (10 points)

L1-053 electronic test (10 points)

It is said that Wang Xingren's IQ can reach the level of human 4-year-old children, and some smart Wang can do addition calculations. For example, if you put two piles of small balls on the ground, one ball and two balls respectively, smart Wang will use "Wang! Wang! Wang!" Indicates that the result of 1 plus 2 is 3.

This problem requires you to do a simulation program for the electronic pet Wang, calculate the sum according to the number of two piles of small balls recognized by the electronic eye, and give the answer with the cry of Wang Xingren.

Input format:

Enter the positive integers A and B in two [1, 9] intervals in one line, separated by spaces.

Output format:

Output A + B Wang! In one line!.

Input example:

2 1

Output example:

Wang!Wang!Wan

#include<stdio.h> int main(void) { int A; int B; scanf("%d %d",&A,&B); for(int i=1;i<=A+B;i++) printf("Wang!"); return 0; }

## 48. Who is the winner (10 points)

L1-055 who is the winner (10 points)

The entertainment program of a TV station has a performance evaluation link. Two artists are arranged to perform each time. Their victory or defeat is jointly decided by the audience vote and the vote of three judges. The rule is: if an artist has a high number of audience votes and is recognized by at least one judge, the artist will win; Or artists with low audience votes, but recognized by all judges, can also win. The program guarantees an odd number of viewers to vote, so there is no flat vote. Please use the program to judge who is the winner.

Input format:

Input the first line to give two positive integers Pa and Pb not exceeding 1000, which are the number of audience votes obtained by artist a and artist b respectively. Make sure the two numbers are not equal. Then the second line gives the voting results of the three judges. The number 0 for a and the number 1 for b are separated by a space.

Output format:

Output data in the following format:

The winner is x: P1 + P2

Where x is the letter representing the winner, P1 is the number of audience votes obtained by the winner, and P2 is the number of judges' votes obtained by the winner.

Input example:

327 129

1 0 1

Output example:

The winner is a: 327 + 1

Thanks to Li Dong from the software school of Anyang Normal University for improving the test data.

Author: Chen Yue

Setting: Zhejiang University

Time limit: 400 ms

Memory limit: 64 MB

#include<stdio.h> int main(void) { int Pa; //a number of votes obtained int Pb; //b number of votes obtained int num; //Judges vote int a=0,b=0; //Calculate the total votes of judges a and b scanf("%d %d",&Pa,&Pb); for(int i=0;i<3;i++) { scanf("%d",&num); if(num==0) a++; else b++; } if(Pa>Pb&&a!=0) printf("The winner is a: %d + %d\n",Pa,a); else if(Pa<Pb&&b!=0) printf("The winner is b: %d + %d\n",Pb,b); else if(Pa<Pb&&a==3) printf("The winner is a: %d + %d\n",Pa,a); else if(Pa>Pb&&b==3) printf("The winner is b: %d + %d\n",Pb,b); }

## 49. Weight removal of linked list (25 points)

L2-002 linked list weight removal (25 points)

Given a linked list L with integer key values, you need to delete the key value nodes with duplicate absolute values. That is, for each key value K, only the node with the first absolute value equal to K is reserved. At the same time, all deleted nodes must be saved in another linked list. For example, given that l is 21 → - 15 → - 15 → - 7 → 15, you need to output the de duplicated linked list 21 → - 15 → - 7 and the deleted linked list - 15 → 15.

Input format:

Enter the address of the first node of L given in the first line and a positive integer N (≤ 10)

5

, is the total number of nodes). The address of a node is a nonnegative 5-bit integer, and the NULL address is represented by − 1.

Then N lines, each describing a node in the following format:

Address key value next node

The address is the address of the node, and the key value is the absolute value, which does not exceed 10

4

The next node is the address of the next node.

Output format:

First output the linked list after de duplication, and then output the deleted linked list. Each node occupies one line and is output according to the input format.

Input example:

00100 5

99999 -7 87654

23854 -15 00000

87654 15 -1

00000 -15 99999

00100 21 23854

Output example:

00100 21 23854

23854 -15 99999

99999 -7 -1

00000 -15 87654

87654 15 -1

#include <stdio.h> #include <string.h> #include <math.h> #define N 10*10*10*10*10+1 struct Node { int jian,xia; //jian → key position, xia → next node }node[N]; int main() { int l,n; //l → first address, n → how many addresses, how many rounds int first; //Starting address of each round int i,j; //Used for loops and array subscripts int tmp[10001]={0}; //When splitting a linked list with a loop, check whether the subscript has appeared. If it does, assign it to the deleted linked list int one[N],two[N]; // one → indicates the linked list after de duplication, and two → indicates the deleted linked list int o=0,t=0; int num; //num gets the key value of each address scanf("%d%d",&l,&n); for(i=0;i<n;i++) { scanf("%d",&first); scanf("%d%d",&node[first].jian,&node[first].xia); } for(i=l;node[i].xia != -1;) { int num=abs(node[i].jian); if(tmp[num]==0) { tmp[num]=1; one[o++]=i; //Storage address } else { two[t++]=i; } i=node[i].xia; } num=abs(node[i].jian);//Notice the last subscript here if(tmp[num]==0) { one[o++]=i;} else { two[t++]=i;} printf("%05d %d ",one[0],node[one[0]].jian); for(j=1;j<o;j++) { printf("%05d\n",one[j]); printf("%05d %d ",one[j],node[one[j]].jian); } printf("%d\n",-1); if(t!=0) //The case that the linked list has not been deleted needs to be judged { printf("%05d %d ",two[0],node[two[0]].jian); for(j=1;j<t;j++) { printf("%05d\n",two[j]); printf("%05d %d ",two[j],node[two[j]].jian); } printf("%d\n",-1); } return 0; }

## 50. Hall of fame and vouchers (25 points)

L2-027 Hall of fame and vouchers (25 points)

For MOOC in Chinese Universities( http://www.icourse163.org/ )Students studying the "data structure" course, if they want to obtain a qualification certificate, the total score must reach 60 points or above, and there are additional benefits: those with a total score within the [G, 100] range can get a 50 yuan PAT voucher; Those who are within the range of [60, G) can get a 20 yuan PAT voucher. The national examination center is universal and valid for one year. At the same time, the teacher will include the top K students in the general evaluation results in the course "Hall of fame". Please write a program to help the teacher list the students in the hall of fame and count the total par value of PAT vouchers issued.

Input format:

Input three integers given in the first line, which are n (positive integers no more than 10000, the total number of students), G (integers in the (60100) interval, the boundary of voucher grade described in the question plane) K (a positive integer no more than 100 and no more than N, which is the lowest ranking in the hall of fame). Next N lines, each line gives a student's account number (a string no more than 15 characters in length and without spaces) and the total score (an integer in the interval [0, 100]), separated by spaces. The title ensures that there are no duplicate accounts.

Output format:

First, output the total face value of the issued PAT voucher in one line. Then, the ranking, account number and score of the students entering the hall of fame are output in non ascending order of the total score, separated by a space. It should be noted that students with the same scores enjoy parallel ranking. When ranking in parallel, they are output in ascending order according to the alphabetical order of the account.

Input example:

10 80 5

cy@zju.edu.cn 78

cy@pat-edu.com 87

1001@qq.com 65

uh-oh@163.com 96

test@126.com 39

anyone@qq.com 87

zoe@mit.edu 80

jack@ucla.edu 88

bob@cmu.edu 80

ken@163.com 70

Output example:

360

1 uh-oh@163.com 96

2 jack@ucla.edu 88

3 anyone@qq.com 87

3 cy@pat-edu.com 87

5 bob@cmu.edu 80

5 zoe@mit.edu 80

Original title link:

L2-027 Hall of fame and vouchers (25 points)

#include<stdio.h> #include<string.h> #include<stdlib.h> struct stu{ int id;//Ranking char edu[25];//account number int score;//achievement }; //Sorting algorithm? int cmp(const void * a,const void * b) { struct stu aa = *(struct stu *)a; struct stu bb = *(struct stu *)b; if(aa.score == bb.score) return strcmp(aa.edu,bb.edu); //When the results are the same, shall we compare the accounts? else return aa.score > bb.score ? -1 : 1; } int main() { int N,G,K; struct stu stud[10005]; while(scanf("%d%d%d",&N,&G,&K) != EOF){ int i; int ans = 0; for(i = 0 ; i < N ; i++){ scanf("%s %d",stud[i].edu,&stud[i].score); if(stud[i].score >= 60 && stud[i].score < G){ ans += 20; } if(stud[i].score >= G && stud[i].score <= 100){ ans += 50; } } printf("%d\n",ans);//Export voucher? qsort(stud,N,sizeof(stud[0]),cmp); int num = 1; stud[0].id = 1; for(i = 1 ; i < N ; i++) //How to deal with the ranking problem after ranking? { num++; if(stud[i].score == stud[i-1].score){ stud[i].id = stud[i-1].id; }else{ stud[i].id = num; } } for(i = 0 ; i < K ; i++) printf("%d %s %d\n",stud[i].id,stud[i].edu,stud[i].score); int k = K; while(stud[K-1].score == stud[k].score){//Judge whether there are students ranking less than or equal to k after outputting K students? printf("%d %s %d\n",stud[k].id,stud[k].edu,stud[k].score); k++; } } return 0; }

## 51. Change (30 points)

L3-001 change (30 points)

Han Meimei likes shopping all over the universe. Now she went to a Martian shop and found that the shop had a special rule: you can pay in coins of any planet, but you can't change, and of course you can't owe. Han Meimei has 10 on hand

4

This is a coin from various planets. Please help her calculate whether it is possible to accurately figure out the amount to be paid.

Input format:

The first line of input gives two positive integers: N (≤ 10

4

) is the total number of coins, M (≤ 10)

2

) is the amount Han Meimei has to pay. The second line gives the positive integer face value of N coins. Numbers are separated by spaces.

Output format:

Output the denomination V of coins in one line

1

≤V

2

≤⋯≤V

k

, condition V is satisfied

1

+V

2

+...+V

k

=M. Numbers shall be separated by 1 space, and there shall be no extra space at the beginning and end of the line. If the solution is not unique, the minimum sequence is output. If there is No Solution, No Solution is output.

Note: we say that the sequence {A[1],A[2],...} is "smaller" than {B[1],B[2],...}, which means that there is k ≥ 1 so that A[i]=B[i] holds for all I < K, and a [k] < B [k].

Input example 1:

8 9

5 9 8 7 2 3 4 1

Output example 1:

1 3 5

Input example 2:

4 8

7 2 4 3

Output example 2:

No Solution

Original title link:

L3-001 change (30 points)

#include<stdio.h> #include<algorithm> #include<vector> using namespace std; int values[10001],dp[101],choose[10001][101]; bool cmp(int a,int b) { return a>b; } int main() { int i,j,n,m,k,t; scanf("%d %d",&n,&m); for(i=1;i<=n;i++) { scanf("%d",&values[i]); } sort(values+1,values+n+1,cmp); for(i=1;i<=n;i++) { for(j=m;j>=values[i];j--) { if(dp[j]<=dp[j-values[i]]+values[i]) { choose[i][j]=1; dp[j]=dp[j-values[i]]+values[i]; } } } if(dp[m]!=m) { printf("No Solution\n"); return 0; } int index=n,sum=m; vector<int> arr; while(sum>0) { if(choose[index][sum]==1) { arr.push_back(values[index]); sum-=values[index]; } index--; } for(i=0;i<arr.size();i++) { if(i==0) { printf("%d",arr[i]); } else { printf(" %d",arr[i]); } } printf("\n"); return 0; }

## 52. The (3n+1) conjecture that killing people does not pay for their lives (15 points)

1001 (3n+1) conjecture that killing people does not pay for their lives (15 points)

Callatz conjectures:

For any positive integer n, if it is even, cut it in half; If it is odd, cut (3n+1) in half. This has been repeatedly cut down, and finally you must get n=1 at a certain step. Karaz announced this conjecture at the World Conference of mathematicians in 1950. It is said that at that time, the teachers and students of Yale University mobilized together to try their best to prove this seemingly silly and naive proposition. As a result, the students did not want to study and only proved (3n+1), so that some people said it was a conspiracy. Karaz was deliberately delaying the progress of teaching and scientific research in American Mathematics

Our topic today is not to prove the karatz conjecture, but to simply count any given positive integer n not exceeding 1000. How many steps (cuts) do we need to get n=1?

Input format:

Each test input contains one test case, which gives the value of positive integer n.

Output format:

Output the number of steps required to calculate from n to 1.

Input example:

3

Output example:

5

Original title link: 1001 (3n+1) conjecture that killing people does not pay for their lives (15 points)

#include<stdio.h> int main() { int i,j; int n; int k=0; scanf("%d",&n); if(n==0){ printf("0");return 0; } for(i=0;;i++) { if(n%2==0) n/=2; else { n= (3*n+1)/2; } k++; if(n==1) break; } printf("%d",k); }

## 53. Write this number (20 points)

1002 write this number (20 points)

Read a positive integer n, calculate the sum of its digits, and write each digit of the sum in Chinese pinyin.

Input format:

Each test input contains one test case, which gives the value of the natural number n. Here we guarantee that n is less than 10

100

.

Output format:

For each digit of the sum of the numbers of n output in a line, there is 1 space between the Pinyin digits, but there is no space after the last Pinyin digit in a line.

Input example:

1234567890987654321123456789

Output example:

yi san wu

Original title link: 1002 write this number (20 points)

#include<stdio.h> #include<string.h> #include<stdlib.h> int main() { int k=0; int sum=0,i=0,j; char n[1001]; gets(n); int len = strlen(n); for(i=0;i<len;i++) { sum+=n[i]-'0'; } //printf("%d\n",sum); // Did the debugging get 135? int dayin[10]; //printf("%d\n",lenght); i=0; while(sum!=0) { dayin[i++]=sum%10; sum/=10; } for(j=i-1;j>=0;j--) { if(j!=0){ switch(dayin[j]) { case 1:printf("yi ");break; case 2:printf("er ");break; case 3:printf("san ");break; case 4:printf("si ");break; case 5:printf("wu ");break; case 6:printf("liu ");break; case 7:printf("qi ");break; case 8:printf("ba ");break; case 9:printf("jiu ");break; case 0:printf("ling ");break; } } else { switch(dayin[j]) { case 1:printf("yi");break; case 2:printf("er");break; case 3:printf("san");break; case 4:printf("si");break; case 5:printf("wu");break; case 6:printf("liu");break; case 7:printf("qi");break; case 8:printf("ba");break; case 9:printf("jiu");break; case 0:printf("ling");break; } } } return 0; }

## 54. I want to pass! (20 points)

1003 I want to pass! (20 points)

"Correct answer" is the most gratifying reply given by the automatic question judgment system. This question belongs to PAT's "correct answer" distribution - as long as the read string meets the following conditions, the system will output "correct answer", otherwise it will output "wrong answer".

The conditions for getting "correct answer" are:

The string must contain only three characters: P, A and T, and cannot contain other characters;

Any string shaped like xPATx can get "correct answer", where x is either an empty string or A string composed of only the letter A;

If aPbTc is correct, aPbATca is also correct, where a, b and c are either empty strings or strings composed of only the letter A.

Now please write an automatic referee program for PAT to determine which strings can get the "correct answer".

Input format:

Each test input contains 1 test case. The first line gives a positive integer n (< 10), which is the number of strings to be detected. Next, each string occupies one line. The length of the string does not exceed 100 and does not contain spaces.

Output format:

The detection result of each string occupies one line. If the string can obtain "correct answer", output YES, otherwise output NO.

Input example:

8

PAT

PAAT

AAPATAA

AAPAATAAAA

xPATx

PT

Whatever

APAAATAA

Output example:

YES

YES

YES

YES

NO

NO

NO

NO

Original title link: 1003 I want to pass! (20 points)

#include<stdio.h> int main() { int n; scanf("%d",&n); while(n--){ char str[110]; int np=0,nt=0,other=0,lp,lt; scanf("%s",str); int len=strlen(str); for(int i=0;i<len;i++){ //Record the number of P,T and other letters and the position of P and T if(str[i]=='P'){ np++; lp=i; }else if(str[i]=='T'){ nt++; lt=i; }else if(str[i]!='A') other++; } if((np!=1)||(nt!=1)||(other!=0)||(lt-lp<=1)){//The number of P and T must be one. There are no other letters. There is at least one A between P and T printf("NO\n"); continue; } int x=lp,y=lt-lp-1,z=len-lt-1; if(x*y==z) printf("YES\n"); else printf("NO\n"); } return 0; }

## 55. Output integer in another format (15 points)

1006 output integer in another format (15 points)

Let's use the letter B to represent "100", the letter S to represent "ten", and 12... N to represent non-zero digit n (< 10). Change the format to output any positive integer no more than 3 bits. For example, 234 should be output as BBSSS1234, because it has 2 "hundreds", 3 "tens", and 4 bits.

Input format:

Each test input contains one test case, giving a positive integer n (< 1000).

Output format:

The output of each test case occupies one line and is output in the specified format n.

Input example 1:

234

Output example 1:

BBSSS1234

Input example 2:

23

Output example 2:

SS123

Original title link: 1006 output integer in another format (15 points)

#include<stdio.h> #include<string.h> #include<stdlib.h> int main() { int n; int i=0,j,num=1; int k[100]={0},k1=0; scanf("%d",&n); while(n!=0) { k[k1++]=n%10; n/=10; } int ci=k1; for(i=k1-1;i>=0;i--) { if(ci==3) { while(k[i]--){ printf("B"); } } else if(ci==2) { while(k[i]--){ printf("S"); } } else { while(k[i]--){ printf("%d",num); num++; } } ci--; } return 0; }

## 56. Prime pair conjecture (20 points)

1007 prime pair conjecture (20 points)

Let's define d

n

Is: d

n

=p

n+1

−p

n

Where p

i

Is the i-th prime. Obviously, d

1

= 1 and d for n > 1

n

It's an even number. "Prime pair conjecture" holds that "there are infinite pairs of adjacent prime numbers with a difference of 2".

Now any positive integer n (< 10) is given

5

) please calculate the number of prime pairs satisfying the conjecture that do not exceed N.

Input format:

The input gives a positive integer N on one line.

Output format:

Output the number of prime pairs satisfying the conjecture that do not exceed N in one line.

Input example:

20

Output example:

4

Original title link: 1007 prime pair conjecture (20 points)

#include<stdio.h> #include<math.h> int main() { int i,j; int r=0; int n; int a[2900],k=0; scanf("%d",&n); for(i=5;i<=n;i+=2) { for(j=3;j*j<=i;j+=2){ if(i%j==0) break; } if(j==i) a[k++]=i; //Save all primes of 2~n } for(i=0;i<k;i++) { if(a[i+1]-a[i]==2) r++; } printf("%d\n",r); }

## 57. Circular right shift of array elements (20 points)

1008 circular right shift of array elements (20 points)

There are N (> 0) integers in an array A. on the premise that other arrays are not allowed, move each integer to the right by M (≥ 0) positions, that is, the data in a is changed from (a)

0

A

1

⋯A

N−1

Convert to (A)

N−M

⋯A

N−1

A

0

A

1

⋯A

N−M−1

) (the last M number cycles to the first M positions). If it is necessary to consider that the program moves data as few times as possible, how to design the moving method?

Input format:

Each input contains a test case. On the first line, enter N (1 ≤ N ≤ 100) and M (≥ 0); on the second line, enter N integers separated by spaces.

Output format:

In one line, the integer sequence after M bits of cyclic right shift is output, separated by spaces, and there can be no redundant spaces at the end of the sequence.

Input example:

6 2

1 2 3 4 5 6

Output example:

5 6 1 2 3 4

Original title link: 1008 circular right shift of array elements (20 points)

#include<stdio.h> int main() { int kr[100],k=0; int n,m; int i,j; scanf("%d%d",&n,&m); m%=n; //△ attention should be paid to the situation of N < m, so it is required to ensure that it can be printed normally for(i=0;i<n;i++) //Print the beginning first, which is equivalent to moving the array to the right by m bits scanf("%d",&kr[i]); for(i=n-m;i<n;i++) printf("%d ",kr[i]); for(i=0;i<n-m;i++) // { if(i!=n-m-1) printf("%d ",kr[i]); else printf("%d",kr[i]); } /* The second output mode: very powerful and classic*/ /* for (int i = 0;i < N - M - 1;i++) printf("%d ", ary[i]); printf("%d", ary[N - M - 1]); */ }

## 58. Irony (20 points)

Given an English sentence, you are required to write a program to output all the words in the sentence in reverse order.

Input format:

The test input contains a test case that gives a string with a total length of no more than 80 in one line. The string consists of several words and several spaces. The word is a string composed of English letters (case sensitive). The words are separated by one space. Input to ensure that there are no redundant spaces at the end of the sentence.

Output format:

The output of each test case occupies one line, and the sentences in reverse order are output.

Input example:

Hello World Here I Come

Output example:

Come I Here World Hello

#include<stdio.h> #include<string.h> #include<stdlib.h> int main() { int i=0,j; char c; char str[100][100]; int dan=80; //Although each group of words is input in positive order, the subscript is controlled here, so the words will be automatically arranged from the end to the front while((c=getchar())!='\n') { if(c==' ') { str[dan][i]='\0'; dan--; i=0; continue; } else { str[dan][i]=c; i++; } } str[dan][i]='\0'; //After the line breaks, you jump out of the loop, so remember to fill in the terminator for the last word for(i=dan;i<80;i++) //Although this is a positive sequence loop, it is because the input is in reverse order printf("%s ",str[i]); printf("%s",str[i]); //The last word entered has no spaces }

## 59. Derivation of univariate polynomial (25 points)

1010 derivation of univariate polynomial (25 points)

Design function to find the derivative of univariate polynomial. (Note: x)

n

The first derivative of (n is an integer) is nx

n−1

. )

Input format:

Enter non-zero coefficients and exponents of polynomials in exponential descending mode (absolute values are integers no more than 1000). Numbers are separated by spaces.

Output format:

The coefficients and exponents of the nonzero terms of the derivative polynomial are output in the same format as the input. Numbers are separated by spaces, but there must be no extra spaces at the end. Note that the exponent and coefficient of "zero polynomial" are 0, but expressed as 0.

Input example:

3 4 -5 2 6 1 -2 0

Output example:

12 3 -10 1 6 0

Original title link: 1010 derivation of univariate polynomial (25 points)

#include<stdio.h> int main() { int k=0; int xi,zhi; while(scanf("%d %d",&xi,&zhi)!=EOF) { if(zhi) //The case where the index is 0 does not exist, so no output is required { if(k!=0) putchar(' '); k++; printf("%d %d",xi*zhi,zhi-1); //Coefficient multiplied by index, index - 1 } } if(k==0) //The derivative is 0. To output "0" printf("0 0\n"); return 0; }

## 60, A+B and C (15 points)

1011 A+B and C (15 points)

Given interval [− 2]

31

,2

31

], please judge whether A+B is greater than C.

Input format:

Input line 1 gives A positive integer T (≤ 10), which is the number of test cases. Then, T groups of test cases are given, each group occupies one line, and A, B and C are given in order. Integers are separated by spaces.

Output format:

For each group of test cases, output Case #X: true in one line. If a + b > C, otherwise output Case #X: false, where X is the number of test cases (starting from 1).

Input example:

4

1 2 3

2 3 4

2147483647 0 2147483646

0 -2147483648 -2147483647

Output example:

Case #1: false

Case #2: true

Case #3: true

Case #4: false

#include<stdio.h> int main() { //Note that because the input data is very large, it should be defined as long to ensure that the data is not lost and the result is the most accurate int i; int k=1; long sum=0; int n; long a,b,c; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%ld%ld%ld",&a,&b,&c); sum=a+b; if(sum>c) printf("Case #%d: true\n",k); else printf("Case #%d: false\n",k); k++; } }