PTA 520 Diamond Tournament 2023 Supplementary Questions

520-1 520 endless love

Score 5 Author Chen Yue Unit Zhejiang University

“I Love You 1000 Times” is a song performed by The Platters in 2019. On the day of 520, Puzzle A asks you to implement a small function to replace the number 1000 with any number entered by the user, and then output the confession in the sentence pattern of the song title. Of course, here replace the English I Love You with the Chinese 520.

Input format:

The input gives a positive integer N not less than 100 and not more than 10 000 in one line, which is a number that the user wants to output.

Output format:

Output the confession on one line in the following format:

520 N Times!

Enter sample:

6666

Output sample:

520 6666 Times!

AC:

#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
printf("520 %d Times!\\
", n);
return 0;
}

520-2 Cardiac Index

Score 10 Author Chen Yue Unit Zhejiang University

One person’s “heartbeat index” for another person is an integer in the interval [?100,100], and the larger it is, the more they like it. When the heartbeat index of A to B reaches or exceeds a given threshold T, it is said that A is “attracted” to B.
This question requires you to judge the relationship between the two of you based on your emotional index for someone and ta’s emotional index for you, and this relationship is represented by an emoji. The rules are as follows:

  • If you are tempted by ta, and ta is also tempted by you, output *^_^*;
  • If you are attracted to ta, but ta is not attracted to you, then output T_T;
  • If you are not tempted by ta, but ta is tempted by you, output -_-#;
  • If you are not tempted by ta, and ta is not tempted by you, then output -_-;

Input format:

The input gives three integers in the interval [?100,100] in one line, followed by a given threshold T, your heartbeat index for ta, and ta’s heartbeat index for you.

Output format:

Output the corresponding emoji on one line.

Enter sample:

60 80 70

Output sample:

*^_^*

AC:

#include <bits/stdc++.h>
using namespace std;
int main(){
int a, b, t;
cin >> t >> a >> b;
if(a < t & amp; & amp; b < t){
puts("-_-");
}else if(a < t & amp; & amp; b >= t){
puts("-_-#");
}else if(a >= t & amp; & amp; b < t){
puts("T_T");
}else if(a >= t & amp; & amp; b >= t){
puts("*^_^*");
}
    
    return 0;
}

520-3 Don’t be afraid, love!

Score 10 Author Chen Yue Unit Zhejiang University

When an ancient girl had a sweetheart, she would quietly break a branch, pull the leaves on that branch, pull a leaf and say “love me”, and another leaf and say “don’t love me”… In this way, when the last leaf is pulled off , to see if it stops at “love” or “don’t love”.

In this question, you are asked to tell your users whether to start with “love” or “not to love” according to the number of leaves on the branches, and finally stop at “love”.

Input format:

Enter a positive integer N (≤30) in the first line, which is the number of users who came to consult. Followed by N lines, each line gives a positive integer not exceeding 100, which is the number of leaves on the branch in the user’s hand.

Output format:

For each query from the user, output your suggestion on one line: Love! if the suggestion starts with “love”, otherwise !Love.

Sample input:

2
18
9

Sample output:

!Love
Love!

AC:

#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
while (n--) {
int x; cin >> x;
if (x % 2 == 0) puts("!Love");
else puts("Love!");
}
return 0;
}

520-4 is a natural pair

Score 15 Author Chen Yue Unit Zhejiang University

The best marriage matching table of the 12 zodiac signs found on the Internet is as follows:
1. Rat: Dragon, Monkey and Ox are compatible with Rat, while Horse, Rabbit and Sheep are not suitable for marriage.
2. Ox: Rat, Snake, and Rooster are compatible with Ox; while Goat, Horse, and Dog are not suitable for marriage.
3. Tigers: Horses and dogs are compatible with tigers, while monkeys and snakes are not suitable for marriage.
4. Rabbit: Sheep, dog, and pig are compatible with rabbits; while rooster and rat are not suitable for marriage.
5. Dragon: Rat, monkey, and rooster are compatible with dragons; while dogs are not suitable for marriage.
6. Snake: Ox and Rooster are compatible with snakes, while pigs and tigers are not suitable for marriage.
7. Horse: Tiger, Goat, and Dog are compatible with Horse; while Rat and Ox are not suitable for marriage.
8. Sheep: Rabbit, horse, and pig are compatible with sheep; while ox and dog are not suitable for marriage.
9. Monkey: Rat and Dragon are compatible with monkeys, while tigers and pigs are not suitable for marriage.
10. Rooster: Ox, Dragon and Snake are compatible with Rooster, while Rabbit is not suitable for marriage.
11. Dogs: Tigers, Rabbits, and Pigs are suitable for dogs; while Dragons and Ox are not suitable for marriage.
12. Pig: Rabbit, Dragon, and Pig are compatible with pigs; while snakes and monkeys are not suitable for marriage.
In this question, you are asked to realize a cyber fortune teller, and judge for the lovers who come to consult whether they are compatible in the zodiac.

Note: The matching relationship above is not completely symmetrical, but it doesn’t matter, we default here that A and B are suitable, so B must be compatible with A.

Input format:

For convenience, we have numbered them from 1 to 12 in the order of the 12 zodiac signs (ie: Rat Ox Tiger Rabbit Dragon Snake Horse Goat Monkey Rooster Dog Pig). The input first gives the corresponding relationship of each zodiac with and without the zodiac. The format is as follows:

zodiac number
Compatible Zodiac Number n Zodiac 1 ... Zodiac n
Zodiac number m does not match Zodiac 1 ... Zodiac m

The title guarantees that the corresponding relationship given is consistent with the title.
A positive integer N (≤60) is given in the next line, which is the number of users who come to consult. Then there are N lines, and each line gives the genus of a pair of lovers. Separate the two attributes with a space.

Output format:

For each query from the user, output your suggestion in one line: if the zodiac sign matches, output Yes; if the genus sign does not match, output No; If not, output NA (meaning Not Available).

Sample input:

1
3 5 9 2
3 7 4 8
2
3 1 6 10
3 8 7 11
3
2 7 11
2 9 6
4
3 8 11 12
2 10 1
5
3 1 9 10
1 11
6
2 2 10
2 12 3
7
3 3 8 11
2 1 2
8
3 4 7 12
2 2 11
9
2 1 5
2 3 12
10
3 2 5 6
1 4
11
3 3 4 12
2 5 2
12
3 4 5 12
2 6 9
3
8 4
3 9
2 5

Sample output:

Yes
no
NA

AC:

#include <bits/stdc++.h>
using namespace std;
vector<int> v[13];
int main(){
int t, n, m, x;
for(int i = 1; i <= 12; + + i){
cin >> t;
cin >> n;
while(n--){
cin >> x;
v[t].emplace_back(x);
}
cin >> m;
while(m--){
cin >> x;
v[t]. emplace_back(-1 * x);
}
}
cin >> n;
while(n--){
int a, b, fg = 0;
cin >> a >> b;
for(int i = 0; i < v[a].size(); + + i){
if(v[a][i] == b){
fg = 1;
break;
}else if(v[a][i] == -b){
fg = 2;
break;
}
}
if(fg == 0){
for(int i = 0; i < v[b].size(); + + i){
if(v[b][i] == a){
fg = 1;
break;
}else if(v[b][i] == -a){
fg = 2;
break;
}
}
}
if(fg == 1) puts("Yes");
else if(fg == 2) puts("No");
else if(fg == 0) puts("NA");
}
    
    return 0;
}

520-5 Knockdowns

Score 15 Author Chen Yue Unit Zhejiang University

We have seen that when the numbers 0-9 are reversed, some numbers cannot be recognized, such as 2, 3, 4, 5, 7; some numbers do not seem to have changed much, such as 0, 1, 8; Some numbers become another number, such as 6 becomes 9, 9 becomes 6.

Given a bunch of numbers, please judge whether each number may be formed by another number being overturned.

Input format:

The input gives a positive integer n (≤20) in the first line, followed by n lines, each of which gives a number with no more than 100 digits.

Output format:

For each given number, if it is possible to be inverted by another number, output the original number before the overturn; if not possible, output bu ke neng.

Sample input:

4
10086
233
9999
17456

Sample output:

10089
bu ke neng
6666
bu ke neng

PA:

#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
while (n--) {
int fg = 0;
string s, tmp; cin >> s;
for (int i = 0; s[i]; + + i) {
if (s[i] == '0' || s[i] == '1' || s[i] == '8') {
tmp + = s[i];
fg = 1;
}
else if (s[i] == '6') {
tmp + = '9';
fg = 1;
}
else if (s[i] == '9') {
tmp + = '6';
fg = 1;
}
else if(s[i] == '2' || s[i] == '3' || s[i] == '4' || s[i] == ' 5' || s[i] == '7') {
fg = 0;
break;
}
}
if(fg == 1) cout << tmp << endl;
if(fg == 0) puts("bu ke neng");
}

return 0;
}

Reason: I don’t know what’s wrong, it’s weird, I changed the fg to AC

AC:

#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
while (n--) {
int fg = 1;
string s, tmp; cin >> s;
for (int i = 0; s[i]; + + i) {
if (s[i] == '0' || s[i] == '1' || s[i] == '8') {
tmp + = s[i];
}
else if (s[i] == '6') {
tmp + = '9';
}
else if (s[i] == '9') {
tmp + = '6';
}
else if (s[i] == '2' || s[i] == '3' || s[i] == '4' || s[i] == ' 5' || s[i] == '7') {
fg = 0;
break;
}
}
if (fg == 1) cout << tmp << endl;
if (fg == 0) puts("bu ke neng");
}

return 0;
}

520-6 Number of couples

Score 20 Author Chen Yue Unit Zhejiang University

It is not easy to come up with a “couple number”. This number needs to meet the following conditions:

  • The number of couples must be a positive integer with an even number of digits;
  • Divide this number into the first half A and the second half B with the same number of digits, then the digits of A are non-increasing from left to right, and the digits of B are non-decreasing from left to right;
  • Add up the digits of A and B respectively to get the corresponding SA? and SB?, then the parity of SA? and SB? is opposite.

For example, 98762234 is a couple number because it is an 8-digit positive integer; the first half of 9876 digits is strictly decreasing, and the second half of 2234 is non-decreasing; SA?=9 + 8 + 7 + 6=30 is For an even number, SB?=2 + 2 + 3 + 4=11 is an odd number.
This question asks you to find the largest number of couples in a given series of numbers.

Input format:

The first line of input first gives a positive integer N (≤104), followed by N lines, and each line gives an integer whose absolute value is less than 108.

Output format:

In the first line, output the number of lovers among the N given numbers, and output the largest number of lovers in the second line. The title guarantees that this number must exist.

Sample input:

5
-2157
6621138
99123199
3112
98762234

Sample output:

2
98762234

Sample Description:

None of the first 3 numbers in the sample input are couples. Among the last 2 couple numbers, the last number is larger, so it is output.

Idea: In fact, this question is so easy, but I have no time! /(ㄒoㄒ)/~~

AC:

#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ct = 0; cin >> n;
string mx = "";
while (n--) {
string s; cin >> s;
if (s[0] == '-') continue;
if (s. length() % 2 == 1) continue;
int fg = 1, m = s.length() / 2, sa = 0, sb = 0;
for (int i = 0; i + 1 < m; + + i) {
if (s[i] < s[i + 1]) {
fg = 0;
break;
}
}
if (fg) {
for (int i = m; i + 1 < s. length(); + + i) {
if (s[i] > s[i + 1]) {
fg = 0;
break;
}
}
}
if (fg) {
for (int i = 0; i < m; + + i) {
sa + = s[i] - '0';
}
for (int i = m; i < s. length(); + + i) {
sb + = s[i] - '0';
}
}
if (fg) {
if (sa % 2 == sb % 2)
fg = 0;
}
if (fg) {
ct++;
if (mx < s) mx = s;
}
}
cout << ct << endl << mx;
return 0;
}

520-7 Sprinkle dog food

Score 20 Author Chen Yue Unit Zhejiang University

On the Internet, a couple showing affection is called “spreading dog food”, because single people are collectively called “single dogs”.
At a large party, all the guests are seated around a long banquet table. If a couple sits together, the single dogs next to them will be slapped; if they are not sitting together, all the single dogs caught between them will be slapped dog food.
In this question, you are asked to find the single person who has been sprinkled the most dog food (in units of “face”).

Input format:

Input the first line to give a positive integer N (≤ 50 000), which is the logarithm of known couples; then N lines, each line gives a pair of couples-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 (≤ 80 000) is given, which is the total number of people attending the party; the next line gives the M digits in order of seats from left to right Guest IDs, separated by spaces. The problem is to ensure that no one steps on two boats.

Output format:

Output the singleton with the most kibble in one line. List in ascending order of ID if not unique. IDs are separated by 1 space, and there should be no extra spaces at the beginning or end of the line.
The title is guaranteed to have at least one output.

Sample input:

4
11111 22222
33333 44444
55555 66666
77777 88888
10
11111 33333 88888 22222 23333 55555 66666 10000 44444 12345

Sample output:

10000 23333 88888

Note:88888 is attached but single at the party.

Idea: Regarding the interval and the like, the violence will be timed out. At that time, the game was 1 hour to fight for hand speed. I am an old man with hand speed, so I don’t have time to read this question. For the positive solution, apply map mapping, and then make a difference. After the exam, the time machine AC.

AC:

#include <bits/stdc++.h>
using namespace std;
const int M = 80005;
map<string, string> mp;//id->object id
map<string, int> id;//id->subscript
vector<string> ans;
int a[M];//difference array
bool fg[M];//has a partner
int mx;
int main() {
ios::sync_with_stdio(0);
cin. tie(0);
cout. tie(0);
int n; cin >> n;
for (int i = 0; i < n; + + i) {
string a, b;
cin >> a >> b;
mp[a] = b; mp[b] = a;
}
int m; cin >> m;
vector<string> v(m + 1);
for (int i = 1; i <= m; + + i) {
cin >> v[i];
id[v[i]] = i;
}
for (int i = 1; i <= m; + + i) {
int j = id[mp[v[i]]];
if (j != 0) {//There is an object and the object is coming
fg[i] = fg[j] = 1;
if (i + 1 == j) {// sit together
if (j != m) {
a[j + 1] + = 1;
a[j + 1 + 1] -= 1;
}
if (i != 1) {
a[i - 1] + = 1;
a[i] -= 1;
}
}
else if (i < j) {
a[i + 1] + = 1;
a[j] -= 1;
}
}
}
for (int i = 1; i <= m; + + i)
a[i] + = a[i - 1];
for (int i = 1; i <= m; + + i) {
if (fg[i]) continue;
if (a[i] > mx) {
mx = a[i];
ans. clear();
ans. emplace_back(v[i]);
}
else if (a[i] == mx) ans. emplace_back(v[i]);
}
sort(ans.begin(), ans.end());
for (int i = 0; i < ans. size(); + + i) {
if (i) cout << ' ' << ans[i];
else cout << ans[i];
}
return 0;
}

520-8 Blind date meeting

Score 25 Author Chen Yue Unit Zhejiang University

A dating website organized a blind date meeting. The organizer has a sign-in sheet in his hand, listing the guests who came to attend the meeting in order of seat number. But it is very troublesome for the guests to find their seat number according to this table. This question requires you to write a program to help guests attending the meeting find their seat numbers quickly.

Input format:

Enter the first line to give a positive integer N not exceeding 103, which is the registration number of the blind date conference. In the following N lines, line i gives the registration number of the guest with seat number i (i=1,?,N). The registration number is a character string consisting entirely of numbers of no more than 8 characters. Enter guarantees that each guest is assigned only one seat.
The next line gives a positive integer M not exceeding 105, which is the number of guests to be queried. In the following M lines, each line gives the registration number of a guest to be queried.

Output format:

For each guest to be queried, if he has a seat in the venue, output his seat number in one line; otherwise output Sorry, indicating that the seat number does not exist.

Sample input:

5
100013
200233
100001
520077
886759
4
520077
000000
100013
999999

Sample output:

4
sorry
1
Sorry

Idea: Just judge whether the person with this id has a seat number and map it. Note ①Use unordered_map to query to avoid timeout; ②Use scanf to read in to avoid timeout. (However, using an int array is faster than unordered_map~)

AC:

#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
unordered_map<int, int> mp;
int main() {
int n, m;
scanf("%d", &n);
for (int i = 1; i <= n; + + i) {
int x; scanf("%d", &x);
mp[x] = i;
}
scanf("%d", &m);
while (m--) {
int x; scanf("%d", &x);
if (mp[x] == 0) puts("Sorry");
else cout << mp[x] << endl;
}
return 0;
}