# PTA group programming ladder competition (1 ~ 20 questions)

Posted by mighty on Mon, 03 Jan 2022 20:07:37 +0100

## 1. L1-001 Hello World (5 points)

This super simple question has no input.

You only need to output the famous short sentence "Hello World" in one line That's it.

Input example:
nothing
Output example:
Hello World!

```public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

```

## 2. L1-002 printing Hourglass (20 points)

L1-002 printing Hourglass (20 points)
This problem requires you to write a program to print the given symbol into the shape of an hourglass. For example, given 17 "*", it is required to print in the following format

The so-called "hourglass shape" refers to the output of an odd number of symbols per line; Align the center of each line of symbols; The difference in the number of symbols between two adjacent lines is 2; The number of symbols decreases from large to small to 1, and then increases from small to large; The number of leading and trailing symbols is equal.

Given any N symbols, it is not necessarily possible to form an hourglass. The printed hourglass is required to use as many symbols as possible.

Input format:
Input gives a positive integer N (≤ 1000) and a symbol on one line, separated by spaces.

Output format:
First print out the largest hourglass shape composed of a given symbol, and finally output the number of unused symbols in one line.

Input example:
19 *
Output example:

2

```import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int i,j,k;		//For circulation
int n;			//How many positive integers are there
int b=1;		//Indicates the maximum number of rows
int h=1;		//Count rows
int sum=1;		//At least 1 star will be printed
int g=0;		//Determines the elements that print spaces
int index;		//Remember the number of print stars in the second half of the line
String Str;		//Symbol
char c;
Scanner dx = new Scanner(System.in);
n = dx.nextInt();
Str = dx.nextLine();	//Enter a string first
c = Str.charAt(1);		//Then use the method of converting string to character to get character
if(n<7) {
System.out.println(c);
System.out.println(n-1);
System.exit(0);		//Request to terminate JVM
}
else {
while(sum<=n) {
b = b+2;
sum = sum + b*2;
h++;
}
}
h=h-1;		//Because the initial value of K is 1, one more line will be calculated. The real number of lines in the upper and lower parts is to subtract 1
index = h;	//Number of rows in the lower half of protection
sum = sum - 2*b;	//Subtract the maximum number of lines on the upper and lower sides, that is, the number of multiple calculations
sum = n -sum;
for(i=h;i>=1;i--)		//Print the top half [including the middle symbol]
{
for(j=1;j<=g;j++)
System.out.print(" ");
for(k=1;k<=2*i-1;k++)
System.out.print(c);
System.out.println();
g++;
}
for(i=2;i<=index;i++){
for(j=1;j<=(g-2);j++){
System.out.print(" ");
}
for(k=1;k<=2*i-1;k++){
System.out.print(c);
}
System.out.println();
g--;
}
System.out.println(sum);
}
}
```

## 3. L1-003 single digit Statistics (15 points)

L1-003 single digit Statistics (15 points)
Given a k-bit integer N=d
​k−1
​​ 10
​k−1
​​ +⋯+d
​1
​​ 10
​1
​​ +d
​0
​​ (0≤d
​i
​​ ≤9, i=0,⋯,k−1, d
​k−1
> 0), please write a program to count the number of occurrences of each different single digit number. For example, given N=100311, there are 2 zeros, 3 ones, and 1 3.

Input format:
Each input contains one test case, that is, a positive integer N with no more than 1000 bits.

Output format:
For each different bit number in N, the bit number D and the number of occurrences m in n are output in one line in the format of D:M. It is required to output in ascending order of D.

Input example:
100311
Output example:
0:2
1:3
3:1

```import java.util.Scanner;

public class Main {

public static void main(String[] args) {

int shu[] = new int[10];
Scanner sc = new Scanner(System.in);
String a = sc.nextLine();
int len = a.length();
for(int i = 0 ; i < len ; i++) {
shu[a.charAt(i)-48]++;
}
for(int i = 0 ; i < 10 ; i++) {
if(shu[i]!=0)
System.out.println(i+":"+shu[i]);
}

}

}

```

## 4. L1-004 calculated Celsius temperature (5 minutes)

Given a Fahrenheit temperature F, this problem requires writing a program to calculate the corresponding Celsius temperature C. Calculation formula: C=5 × (F−32)/9. The problem is to ensure that the input and output are within the integer range.

Input format:
Input gives a Fahrenheit temperature in one line.

Output format:
In one line, the integer value of the corresponding Celsius temperature C is output in the format "Celsius = C".

Input example:
150
Output example:
Celsius = 65

```import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int f = scanner.nextInt();
System.out.println("Celsius = " + (5*(f-32)/9));
}
}
```

## 5. L1-005 test seat number (15 points)

Each PAT candidate will be assigned two seat numbers when taking the test, one is the test seat and the other is the test seat. Under normal circumstances, the examinee will get the seat number of the test machine first when entering the test machine. After entering the test machine state, the system will display the examinee's test seat number. During the test, the examinee needs to change to the test seat. However, some candidates are late and the test is over. They can only take the test seat number they got to you for help and find out their test seat number from the background.

Input format:
Enter the first line to give a positive integer n (≤ 1000), and then n lines. Each line gives the information of a candidate: ticket number, test seat number, test seat number. The ticket number consists of 16 digits, and the seat number ranges from 1 to N. input to ensure that everyone's ticket number is different, and two people will not be assigned to the same seat at any time.

After the candidate information, give a positive integer M (≤ N), and then give M test seat numbers to be queried in one line, separated by spaces.

Output format:
Corresponding to each test seat number to be queried, the corresponding candidate's admission card number and test seat number are output in one line, separated by a space.

Input example:
4
3310120150912233 2 4
3310120150912119 4 1
3310120150912126 1 3
3310120150912002 3 2
2
3 4
Output example:
3310120150912002 2
3310120150912119 1

```import java.io.BufferedReader;
import java.io.IOException;
import java.util.HashMap;
public class Main{
public static void main(String[] args) throws IOException {
HashMap map = new HashMap();
while(--n>=0){
String s2[]=s.split(" ");
map.put(s2[1],s2[0]+" "+s2[2]);
}
int j=0;
while(--m>=0){
System.out.println(map.get(s3[j]));
j++;
}
}
}
```

## 6. L1-006 continuity factor (20 points)

There may be several consecutive numbers in the factor of a positive integer N. For example, 630 can be decomposed into 3 × five × six × 7, of which 5, 6 and 7 are three consecutive numbers. Given any positive integer N, it is required to write a program to calculate the number of the longest continuous factor and output the smallest continuous factor sequence.

Input format:
Input gives a positive integer N (1 < N < 2) in one line
​31
​​ ).

Output format:
First, the number of longest continuous factors is output in line 1; Then, in line 2, the smallest continuous factor sequence is output in the format of factor 1, factor 2... * factor k, where the factors are output in ascending order, and 1 is not included.

Input example:
630
Output example:
3
567

```import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
long n=s.nextInt();
long start=0,len=0;
long sum=0;
for(int i=2;i<Math.sqrt(n);i++) {
sum=1;
for(int j=i;sum*i<=n;j++) {
sum*=j;
if(n%sum==0&&j-i+1>len) {
start=i;
len=j-i+1;
}
}
}
if(start==0) {
start=n;
len=1;
}
System.out.println(len);
for(int i=0;i<len-1;i++) {
System.out.print(start+i+"*");
}
System.out.print(start+len-1);
}
}
```

## 7. L1-011 A-B (20 points)

This problem requires you to calculate A − B. But the trouble is that both A and B are strings -- that is, delete all the characters contained in string B from string A, and the remaining characters form string A − B.

Input format:
Enter the string A and B in 2 lines. Neither string is longer than 10
​4
And ensure that each string is composed of visible ASCII code and white space characters, and finally ends with a newline character.

Output format:
Print the result string of A − B in one line.

Input example:
I love GPLT! It's a fun game!
aeiou
Output example:
I lv GPLT! It's fn gm!

```#include<stdio.h>
#include<string.h>
int main()
{
int i=0,j=0;			//Used for loops and array subscripts
char str1[10010];		//Used to store A and B strings
char str2[10010];		//Used to store the string letters to be deleted
int length;				//Used to store string length
gets(str1);
gets(str2);
length = strlen(str2);	//Just remember the length of str2 string
while(str1[i]!='\0')	//Take str1 string from the first letter and check it one by one
{
for(j=0;j<length;j++)//Put this letter into str2 and check whether there is a corresponding one one one by one. If there is a corresponding one
{					//Then the for loop will jump out in advance, and the value of j cannot be equal to length,
if(str1[i]==str2[j])//Remember key words, in advance! So from here, we can be sure that if the for loop executes
break;			//In the end, it is proved that this letter cannot be found in str2,
}						//Then naturally, it needs to be displayed!
if(j==length)
printf("%c",str1[i]);
i++;
}
printf("\n");
return 0;
}

```

## 8. L1-012 calculation index (5 points)

I really didn't lie to you. This is a simple problem - for any given positive integer n no more than 10, you are required to output 2
​n
​​ . Isn't it hard?

Input format:
The input gives a positive integer n of no more than 10 in one line.

Output format:
Output 2 in one row according to format 2^n = calculation result
​n
Value of.

Input example:
5
Output example:
2^5 = 32
Author: Chen Yue
Setting: Zhejiang University
Time limit: 400 ms
Memory limit: 64 MB

```#include<stdio.h>
#include<math.h>
int main()
{
int n;
int result;
scanf("%d",&n);
if(n<1 || n>10)		return 0;
result=pow(2,n);
printf("2^%d = %d\n",n,result);
return 0;
}
```

## 9. L1-013 calculate factorial sum (10 points)

For a given positive integer n, you need to calculate s = 1+ 2!+ 3!+…+ N!.

Input format:
The input gives a positive integer N of no more than 10 in one line.

Output format:
Output the value of S in one line.

Input example:
3
Output example:
9
Author: Chen Yue
Setting: Zhejiang University
Time limit: 400 ms
Memory limit: 64 MB

```#include<stdio.h>
int main()
{
int N;
int i;	//For circulation
int sum=0,mix=1;	//Sum
scanf("%d",&N);
if(N<1 || N>10)		return 0;
for(i=1;i<=N;i++)
{
mix=i*mix;
sum=sum+mix;
}
printf("%d\n",sum);
return 0;
}
```

## 10. L1-014 simple question (5 points)

I really didn't lie to you this time - this super simple question has no input.

You only need to output the fact in one line: This is a simple problem That's it.

Input example:
nothing
Output example:
This is a simple problem.

```#include<stdio.h>
int main()
{
printf("This is a simple problem.\n");
return 0;
}

```

## 11. L1-015 draw squares with Obama (15 points)

U.S. President Barack Obama not only called on everyone to learn programming, but even set an example in writing code, becoming the first president to write computer code in U.S. history. At the end of 2014, in order to celebrate the official launch of "Computer Science Education Week", Obama wrote a very simple computer code: draw a square on the screen. Now you draw with him!

Input format:
Enter the square side length N (3 ≤ N ≤ 21) and some character C constituting the square side in one line, separated by a space.

Output format:
Outputs the square drawn by the given character C. However, notice that the row spacing is larger than the column spacing, so in order to make the result look more square, the number of rows we output is actually 50% of the number of columns (rounded).

Input example:
10 a
Output example:
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa

```#include<stdio.h>
int main()
{
int N;
char c;
int i,j;
scanf("%d %c",&N,&c);
if(N%2==0){
for(i=0;i<N/2;i++){
for(j=0;j<N;j++){
printf("%c",c);
}
printf("\n");
}
}else{
for(i=0;i<N/2+1;i++){		//Because the decimal point is 0.5 anyway, so add 1
for(j=0;j<N;j++){
printf("%c",c);
}
printf("\n");
}
}
return 0;
}
```

## 12. L1-016 checking ID card (15 points)

L1-016 checking ID card (15 points)
A legal ID number is composed of 17 regions, date numbers and serial numbers plus 1 bit check codes. The calculation rules of check code are as follows:

First, the first 17 digits are weighted and summed, and the weight distribution is: {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}; Then, the calculated sum is modeled against 11 to obtain the value Z; Finally, the value of Z value and check code M are corresponding according to the following relationship:

Z: 0 1 2 3 4 5 6 7 8 9 10
M: 1 0 X 9 8 7 6 5 4 3 2
Now, with some ID number, please verify the validity of the check code and output the problem number.

Input format:
The first line is input, and the positive integer N (or less than 100) is the number of the ID number. Then N row, each row gives 1 18 ID number.

Output format:
According to the order of input, 1 questions ID number is output on each line. Here, we do not check whether the first 17 digits are reasonable, but only whether the first 17 digits are all numbers and the calculation of the last one check code is accurate. If all numbers are normal, output All passed.

Input example 1:
4
320124198808240056
12010X198901011234
110108196711301866
37070419881216001X
Output example 1:
12010X198901011234
110108196711301866
37070419881216001X
Input example 2:
2
320124198808240056
110108196711301862
Output example 2:
All passed

```#include <stdio.h>
#include <stdlib.h>

int charToInt(char c)
{
return (int)(c-'0');
}
int main(int argc, char *argv[])
{
int n,i,j,k=0,s,
a[]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
char cur,b[11]={'1','0','X','9','8','7','6','5','4','3','2'},
c[20];
scanf("%d",&n);
for(i = 0; i < n;i++)
{
s=0;
scanf("%s",&c);
for(j= 0;j<17;j++)
{
if(c[j]>='0'&&c[j]<='9')
{
s+=charToInt(c[j])*a[j];
}
else
{
printf("%s",c);
if(i<n-1)
{
printf("\n");
}
s=-1;
break;
}
}
if(b[s%11]==c[j]&&s!=-1)
{
k++;
}
else if(b[s%11]!=c[j]&&s!=-1)
{
printf("%s",c);
if(i<n-1)
{
printf("\n");
}
}
}
if(k==n)
{
printf("All passed");
}
return 0;
}
```

## 13. How much is L1-017 (15 points)

How much is L1-017 (15 points)
An integer "the degree of breaking two" is defined as the ratio of the number of 2 contained in the number to its digits. If this number is negative, the degree increases by 0.5 times; If it is still an even number, double it. For example, if the number - 1314222336 is an 11 digit number, including three 2's, and is negative and even, then its offense degree is calculated as: 3 / 11 × one point five × two × 100%, about 81.82%. Please calculate how many two a given integer is.

Input format:
The first line of input gives an integer N of no more than 50 bits.

Output format:
Output the degree of N breaking two in one line, and keep two decimal places.

Input example:
-13142223336
Output example:
81.82%
Thanks to Duan Xiaoyun of Anyang Normal University and Li Fulong of class 5 of software engineering for supplementing the test data!

```#include<stdio.h>
#include<string.h>
int main()
{
char N[50];
int i;
float count=0,sum=0;
scanf("%s",&N);
int x=strlen(N);		//Calculate string length
for(i=0;i<x;i++){		//Calculate how many two
if(N[i]=='2')
count++;
}
if(N[0]=='-'){				//negative
sum=(count/(x-1))*1.5*100;
}else{						//Positive number
sum=count/x*100;
}
if(N[x-1]%2==0)			//even numbers
sum*=2;
printf("%.2f%%",sum);
return 0;
}
```

## 14. L1-018 Big Ben (10 minutes)

L1-018 Big Ben (10 minutes)
On the microblog, a guy who calls himself "Big Ben V" rings the bell every day to urge code farmers to cherish their bodies and go to bed early. However, because the stupid clock doesn't work and rest regularly, it rings the bell irregularly. Generally, the number of points for ringing the bell is determined according to the time of ringing the bell. If it is struck at a certain hour, the "when" number is equal to that integer point; If it's past the whole point, knock down a whole point. In addition, although there are 24 hours a day, the clock only strikes 1 ~ 12 in the second half of the day. For example, when the bell rings at 23:00, it is "dangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdangdang. During the period from 00:00 midnight to 12:00 noon (endpoint time included), the stupid clock does not ring.

Now please write a program to ring Big Ben according to the current time.

Input format:
Enter the first line to give the current time in hh:mm format. Where hh is the hour, between 00 and 23; Mm is the minute, between 00 and 59.

Output format:
Ring the bell for Big Ben according to the current time, that is, output the corresponding number of dangs in one line. If not, output:

Only hh:mm. Too early to Dang.
Where hh:mm is the time entered.

Input example 1:
19:05
Output example 1:
DangDangDangDangDangDangDangDang
Input example 2:
07:05
Output example 2:
Only 07:05. Too early to Dang.

```#include<stdio.h>
main()
{
int m, n,h,i,k;
scanf("%d:%d", &m, &n);
if (m >= 13 && m < 24)
{
h = m - 12;
if (n != 0)
k = h + 1;
else if (n == 0)
k = h;

for (i = 0; i < k; i++)
{
printf("Dang");
}
}
else
printf("Only %02d:%02d.  Too early to Dang.",m,n);
}
```

## 15. L1-019 who falls first (15 points)

L1-019 who falls first (15 points)
Boxing is an interesting part of ancient Chinese wine culture. The method of two people's boxing on the wine table is to shout out a number in each population and draw a number with their hands at the same time. If the number drawn by the loser is exactly equal to the sum of the numbers shouted by the two people, the loser will lose and be fined a glass of wine. If two people win or lose together, they will continue to the next round until the only winner appears.

Below are the drinking capacity (the maximum number of cups you can drink without falling) and stroke records of a and B. please judge who falls first.

Input format:
Enter the first line to give the alcohol consumption of Party A and Party B successively (non negative integer not exceeding 100), separated by spaces. The next line gives a positive integer N (≤ 100), and then N lines, each line gives a record of one round of boxing, in the format of:

A shout a row B shout B row
Among them, shouting is the number shouted, and rowing is the number rowed out, which are positive integers no more than 100 (rowing with both hands).

Output format:
In the first line, output the person who fell first: A for a and B for B. In the second line, output how many drinks the man who didn't pour had. The title guarantees that one person will fall. Note that the program terminates when someone falls, and the subsequent data does not need to be processed.

Input example:
1 1
6
8 10 9 12
5 10 5 10
3 8 5 12
12 18 1 13
4 16 12 15
15 1 1 16
Output example:
A
1

```#include<stdio.h>
int main()

{

int N,A,B;		//A. B. alcohol consumption

int i;

int countA=0,countB=0;

int Ahan[100],Ahua[100],Bhan[101],Bhua[100];

scanf("%d%d",&A,&B);

scanf("%d",&N);

for(i=0;i<N;i++)

scanf("%d%d%d%d",&Ahan[i],&Ahua[i],&Bhan[i],&Bhua[i]);

for(i=0;i<N;i++){

if((Ahua[i]==(Ahan[i]+Bhan[i]))&&(Bhua[i]==(Bhan[i]+Bhan[i])))

continue;

if(Ahua[i]==(Ahan[i]+Bhan[i])){

countA++;				//Cup number plus 1

A--;					//Reduced alcohol consumption

if(A<0){

printf("A\n%d\n",countB);		//count output is not inverted

break;

}

}

else

if(Bhua[i]==(Ahan[i]+Bhan[i])){

countB++;

B--;

if(B<0){

printf("B\n%d\n",countA);

break;

}

}

}

return 0;

}
```

## 16. L1-020 handsome enough to have no friends (20 points)

L1-020 handsome enough to have no friends (20 points)
When all living beings are busy sending photos in their circle of friends, there are always some people who are too handsome to have friends. This question requires you to find those who are so handsome that they have no friends.

Input format:
Input the first line to give a positive integer N (≤ 100), which is the number of known circles of friends; then N lines, each line first gives a positive integer K (≤ 1000), which is the number of people in the circle of friends, and then lists all people in a circle of friends - for convenience, each person corresponds to an ID number, which is 5 digits (from 00000 to 99999), IDS are separated by spaces; then a positive integer M (≤ 10000) is given, which is the number of people to be queried; M IDs to be queried are listed in the next line, separated by spaces.

Note: people without friends can be those who do not have a "circle of friends" installed at all, or those who are only in the circle of friends. Although some narcissists will repeatedly add themselves to the circle of friends, the topic ensures that there are at least two different people in all the circle of friends with K more than 1.

Output format:
Output those handsome people who have no friends in the order of input. ID S shall be separated by 1 space, and there shall be no extra space at the beginning and end of the line. If No one is handsome, output No one is handsome.

Note: the same person can be queried multiple times, but only output once.

Input example 1:
3
3 11111 22222 55555
2 33333 44444
4 55555 66666 99999 77777
8
55555 44444 10000 88888 22222 11111 23333 88888
Output example 1:
10000 88888 23333
Input example 2:
3
3 11111 22222 55555
2 33333 44444
4 55555 66666 99999 77777
4
55555 44444 22222 11111
Output example 2:
No one is handsome

```#include <stdio.h>
#include <string.h>
int love[100010];		//Storage ID number space
int main()
{
int n;			//There are several circles of friends
int k;			//How many people are there in each circle of friends
int m;			//Number of people to be queried
int id;			//id number
int newid;		//id number to be queried
int i,j;		//Used for loops and array subscripts
int flag=0;		//Used to judge whether the output result is because he is too handsome and has no friends
scanf("%d",&n);

for(i=0;i<n;i++)
{
scanf("%d",&k);
for(j=0;j<k;j++)
{
scanf("%d",&id);
if(k == 1)break;//Only their own circle of friends
love[id] = 1;   //Everyone's ID must be different, so let the known value in the circle of friends be 1
}
}
scanf("%d",&m);
for(i=0;i<m;i++)
{
scanf("%d",&newid);
if(!love[newid])//Note here that if the judgment condition is not true, it is false, and if it is true, it already exists
{               //There is no need to output. Using this feature, we just need to put the output that does not exist in advance
if(++flag > 1) printf(" ");
printf("%05d",newid);
love[newid] = 1;
}
}
if(flag == 0) printf("No one is handsome");
printf("\n");
return 0;
}

```

## 17. L1-021 important words three times (5 points)

L1-021 important words three times (5 points)
This super simple question has no input.

You just need to put this very important sentence - "I'm gonna WIN!"—— Just output it three times in a row.

Note that one line is occupied each time, and there shall be no extra characters except the carriage return of each line.

Input example:
nothing
Output example:
I'm gonna WIN!
I'm gonna WIN!
I'm gonna WIN!

```#include <stdio.h>
void f()
{
printf("I'm gonna WIN!\n");
}
int main()
{
f();
f();
f();
return 0;
}
```

## 18. L1-022 parity separation (10 points)

L1-022 parity separation (10 points)
Given N positive integers, please count how many are odd and even?

Input format:
The first line of input gives a positive integer N (≤ 1000); the second line gives N non negative integers separated by spaces.

Output format:
In one row, the number of odd numbers and even numbers are output successively. The middle is separated by 1 space.

Input example:
9
88 74 101 26 15 0 34 22 77
Output example:
3 6

```#include <stdio.h>
int main()
{
int N;				//How many numbers do you want to enter
int i;				//For circulation
int a[1000];		//The maximum array space is given to store input data to prevent subscript out of bounds
int num1=0,num2=0;	//Used to calculate odd \ even numbers
scanf("%d",&N);
if(N<=0 || N>1000) return 0;	//Natural numbers greater than 0 are positive integers
for(i=0;i<N;i++)
scanf("%d",&a[i]);
for(i=0;i<N;i++)
{
if(a[i]%2!=0)
num1++;
else
num2++;
}
printf("%d %d\n",num1,num2);
return 0;
}
```

## 19. L1-023 output GPLT (20 points)

L1-023 output GPLT (20 points)
A string consisting of only English letters with a length of no more than 10000 is given. Please reorder the characters and output them in the order of GPLTGPLT... And ignore other characters. Of course, the number of four characters (case insensitive) is not necessarily the same. If a certain character has been output, the remaining characters are still printed in GPLT order until all characters are output.

Input format:
Input a non empty string consisting of English letters with a length of no more than 10000 in one line.

Output format:
Output the sorted string according to the topic requirements in one line. The title ensures that the output is not empty.

Input example:
pcTclnGloRgLrtLhgljkLhGFauPewSKgt
Output example:
GPLTGPLTGLTGLGLL

```#include<stdio.h>
#include<string.h>
int main()
{
char str[10010];			//Memory space for storing input strings
int g=0,p=0,l=0,t=0;		//These four variables are used to calculate the number of occurrences in the string
int i,j;					//Used for loops and array subscripts
int n;						//Get the length of the input string
gets(str);					//Provide input function
n = strlen(str);			//Get the length of str string and assign it to n
for(i=0;i<n;i++)			//Start with the first letter and find out if there are g, G, t, t, l, l, P and P
{							//If it exists, the number of occurrences will be calculated in the for loop, because each corresponding sequence will be + 1
if(str[i]=='g' || str[i]=='G')
g++;
else if(str[i]=='p' || str[i]=='P')
p++;
else if(str[i]=='l' || str[i]=='L')
l++;
else if(str[i]=='t' || str[i]=='T')
t++;
}
while(n)					//Then there is the output link, which outputs each letter and subtracts 1
{							//Until they are all restored to the initial value of 0, there is no need to print, then n=0 is assigned, and it is judged as false to end the cycle
if(g!=0)
{	printf("G");	g--;	}
if(p!=0)
{	printf("P");	p--;	}
if(l!=0)
{	printf("L");	l--;	}
if(t!=0)
{	printf("T");	t--;	}
if(g==0 && p==0 && l==0 && t==0)
n=0;
}
printf("\n");
return 0;
}

```

## 20. L1-024 the day after tomorrow (5 points)

L1-024 the day after tomorrow (5 points)
If today is Wednesday, the day after tomorrow is Friday; If today is Saturday, the day after tomorrow is Monday. We use the numbers 1 to 7 for Monday to Sunday. Given a certain day, please output the day after tomorrow of that day.

Input format:
The first line of input gives a positive integer D (1 ≤ D ≤ 7), representing a day of the week.

Output format:
The day after tomorrow is the day of the week when D days are output in one line.

Input example:
3
Output example:
5

```#include<stdio.h>
int main()
{
int d;	//input
scanf("%d",&d);
if(d<1 || d>7)	return 0;
if(d<=5)
printf("%d",d+2);
else
printf("%d",d-7+2);
return 0;
}

```

Topics: pta