Keywords: C

# L1-060 psychological shadow area (5 points)

xlyy.JPG

This is a psychological shadow area map. We all think we can move forward at a uniform speed (the blue line in the figure), and in the late stage of procrastination, we often implement the crazy rush at the last minute (the red line in the figure). The area enclosed by the red and blue lines is the psychological shadow area when we do our homework.

Now give the coordinates of the red inflection point (x,y), and ask you to calculate the psychological shadow area.

Input format:
Input two positive integers x and y not exceeding 100 in one line, and ensure that x > y. Here, it is assumed that the maximum values of abscissa and ordinate (i.e. deadline and final completion) are 100.

Output format:
Output psychological shadow area in one line.

Friendly reminder: triangle area = bottom length x height / 2; Rectangular area = bottom edge length x height. It's too complicated. It's a five point subtraction question

Input example:
90 10
No blank lines at the end

Output example:
4000
No blank lines at the end

```#include<bits/stdc++.h>
using namespace std;

int main()
{
double l,w;
cin>>w>>l;
double n=w/(l*l);
printf("%.1f\n",n);
if(n>25)
printf("PANG\n");
else printf("Hai Xing\n");
}

```

# L1-062 lucky lottery (15 points)

The number of a lottery ticket has six digits. If the sum of the first three digits of a lottery ticket is equal to the sum of the last three digits, it is said that the lottery ticket is lucky. This question asks you to judge whether a given lottery ticket is lucky.

Input format:
Input gives a positive integer N (≤ 100) in the first line. Then N lines, each line gives a 6-digit number of a lottery ticket.

Output format:
For each lottery ticket, if it is lucky, output You are lucky!; Otherwise, output Wish you good luck.

Input example:
2
233008
123456
No blank lines at the end

Output example:
You are lucky!
Wish you good luck.
No blank lines at the end

```#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,x;
cin>>n;
while(n--)
{
cin>>x;
int x1=x/1000;
int x2=x%1000;
int a1=x1%10,a2=x1/10%10,a3=x1/100;
int b1=x2%10,b2=x2/10%10,b3=x2/100;
if(a1+a2+a3==b1+b2+b3)printf("You are lucky!\n");
else printf("Wish you good luck.\n");
}
}
```

# L1-063 fish or meat (10 points)

fish.JPG meat.JPG

The national standard height of 8-year-old boy is 130cm and the standard weight is 27kg; The standard height of an 8-year-old girl is 129 cm and the standard weight is 25 kg.

Now you should give nutritional suggestions according to the baby's height and weight.

Input format:
The input gives a positive integer N not exceeding 10 in the first line, and then N lines, each line gives the body data of a baby:

Gender height weight
Where gender is 1 for boys and 0 for girls. Height and weight are positive integers no more than 200.

Output format:

If it is too short, the output is: duo chi yu! (eat more fish);
If it is too thin, output: duo chi rou! (eat more meat);
If the standard is positive, output: wan mei! (perfect);
If it is too high, output: ni li hai! You're great;
If it is too fat, output: shao chi rou! (eat less meat).
Evaluate height first, then weight. There should be a space between two sentences.

Input example:
4
0 130 23
1 129 27
1 130 30
0 128 27
No blank lines at the end

Output example:
ni li hai! duo chi rou!
duo chi yu! wan mei!
wan mei! shao chi rou!
duo chi yu! shao chi rou!
No blank lines at the end

```#include<bits/stdc++.h>
using namespace std;

int main()
{
int n;
cin>>n;
while(n--)
{
int a,l,w;
cin>>a;
if(a==0){
cin>>l>>w;
if(l<129)printf("duo chi yu! ");
else if(l==129)printf("wan mei! ");
else printf("ni li hai! ");
if(w<25)printf("duo chi rou!\n");
else if(w==25)printf("wan mei!\n");
else printf("shao chi rou!\n");
}
else {
cin>>l>>w;
if(l<130)printf("duo chi yu! ");
else if(l==130)printf("wan mei! ");
else printf("ni li hai! ");
if(w<27)printf("duo chi rou!\n");
else if(w==27)printf("wan mei!\n");
else printf("shao chi rou!\n");
}
}
}

```

# L1-064 AI core code valued at 100 million (20 points)

AI.jpg

The above picture is from Sina Weibo.

This question requires you to implement a slightly more valuable AI English Q & a program. The rules are:

No matter what the user says, first print out what the other party says in one line as it is;
Eliminate redundant spaces in the original text: replace multiple spaces between adjacent words with one space, delete all the spaces at the beginning and end of the line, and delete the spaces in front of punctuation marks;
Change all capitalized English letters in the original text into lowercase, except I;
Replace all independent can you and could you in the original text with I can and I could - here "independent" refers to words separated by spaces or punctuation marks;
Replace all independent I and me in the original text with you;
Put all the question marks in the original text? Change to exclamation point!;
Output the replaced sentence in one line as the answer of AI.
Input format:
Input: first, a positive integer N of no more than 10 is given in the first line, and then N lines. Each line gives a user's dialogue with no more than 1000 characters and ending with carriage return. The dialogue is a non empty string, including only letters, numbers, spaces and visible half width punctuation marks.

Output format:
Output according to the requirements of the question surface. AI: and a space should be added before each AI answer.

Input example:
6
Hello ?
Good to chat with you
can you speak Chinese?
Really?
Could you show me 5
What Is this prime? I,don 't know
No blank lines at the end

Output example:
Hello ?
AI: hello!
Good to chat with you
AI: good to chat with you
can you speak Chinese?
AI: I can speak chinese!
Really?
AI: really!
Could you show me 5
AI: I could show you 5
What Is this prime? I,don 't know
AI: what Is this prime! you,don't know

```#include<iostream>
#include<string>

using namespace std;

int judge(char c)
{
if (c >= 'A'&&c <= 'Z') return 1;
if (c >= 'a'&&c <= 'z') return 2;
if (c >= '0'&&c <= '9') return 3;
if (c == ' ') return -1;
return 0;	//punctuation
}
/*
Idea:

Cycle twice

1.The first cycle,
A.Leave one space for multiple spaces, and there is no space before punctuation
B.Change all uppercase letters to lowercase except I;
C.？become!

2.After the first loop, if there are spaces at the beginning of the line, eliminate the spaces

3.The second loop replaces the original "i can", "I could", "I," me“
*/

int main()
{
int m;
cin>>m;
getchar();
while(m--)
{
string s,str;
getline(cin,s);
cout<< s << endl;

//Operation on s[i]
for (int i = 0; s[i]; i++)
{
//Note that the space representation is' '
if(s[i]==' '&&judge(s[i+1])<=0)	//If there are multiple spaces, only one space is left and the space before punctuation is eliminated
continue;

if(judge(s[i])==1&& s[i]!='I')//Change capital letters to lowercase, except I
s[i]=tolower(s[i]);

if (s[i] == '?')
s[i] = '!';

str += s[i];
}
if(str==' ')
str = str.substr(1);	//If it starts with a space, eliminate it

string temp;//Intermediate variables for comparison
s = str;
for(int i = 0; i < s.size(); i++)
{
//Premise of independence
//If i-1 is a space or punctuation mark, intercept i (because this is the beginning of a word)
if(judge(s[i-1])<=0)
{
//Independent backwardness
//temp = "replace word" & & the next character after the replacement word is a space or punctuation mark

temp = s.substr(i,7);					//Replace can you
if(temp == "can you" && judge(s[i+7])<=0)
{
str += "I can";
i += 7;
}

temp = s.substr(i,9); 					//Replace could you
if(temp == "could you" && judge(s[i+9])<=0)
{
str += "I could";
i += 9;
}

temp = s.substr(i,1);
if(temp == "I" && judge(s[i+1])<=0)		//Replace I
{
str += "you";
i += 1;
}

temp = s.substr(i,2);					//Replace me
if(temp == "me" && judge(s[i+2])<=0)
{
str += "you";
i += 2;
}
}

//I don't understand why I should judge
if(i < s.size())                            //If it is not the above replacement words, then
str += s[i];
}

cout<<"AI: "<<str<<endl;
}
}
```

# L1-065? Nonsense code (5 points)

Linus Torvalds, the father of Linux, famously said, "talk is soap. Show me the code." please output this sentence directly on the screen.

Input format:
No input for this question.

Output format:
Output talk is heap. Show me the code. On one line.

Input example:
nothing
No blank lines at the end

Output example:
Talk is cheap. Show me the code.
No blank lines at the end

```print("Talk is cheap. Show me the code.")
```

# L1-066 cat is liquid (5 points)

cat.JPG

It's difficult to measure a person's volume, but cats are different. Because cats are liquids, it's easy to get the volume of cats in a cuboid container by measuring the volume of a cuboid container. Please complete this calculation.

Input format:
Input: three positive integers no more than 100 are given in the first line, corresponding to the length, width and height of the container respectively.

Output format:
Output the volume of the cat in one line.

Input example:
23 15 20
No blank lines at the end

Output example:
6900
No blank lines at the end

```#include<bits/stdc++.h>
using namespace std;

int main()
{
int a,b,c;
cin>>a>>b>>c;
printf("%d\n",a*b*c);
}

```

# L1-067 Roche limit (10 points)

An important plot in the science fiction film wandering the earth is that when the earth is too close to Jupiter, the atmosphere begins to be sucked away by Jupiter, and as it approaches the "rigid Roche limit" of the earth log, the earth is in danger of being completely torn apart. But in fact, this calculation is wrong.

roche.jpg

Roche limit is the distance between the gravitational attraction of a celestial body and the tidal force caused by the second celestial body. When the distance between two celestial bodies is less than the Roche limit, the celestial body tends to break up and then become the ring of the second celestial body. It is named after Edward Roche, the first person to calculate this limit. (excerpted from Baidu Encyclopedia)

The ratio of the density of a large object to the density of a small object to the third power is multiplied by the radius of the large object and a multiple (the multiple corresponding to the fluid is 2.455 and the multiple corresponding to the rigid body is 1.26), which is the value of the Roche limit. For example, the density ratio of Jupiter to the earth to the third power is 0.622. If the earth is assumed to be a fluid, the Roche limit is 0.622 × 2.455 = 1.52701 times the radius of Jupiter; But the earth is a rigid body, and the corresponding Roche limit is 0.622 × 1.26 = 0.78372 times the radius of Jupiter. This distance is smaller than the radius of Jupiter, that is, the earth will be torn up only when it is inside Jupiter. In other words, the earth cannot be torn up.

In this question, please judge whether a small celestial body will be torn apart by a large celestial body.

Input format:
Input: three numbers are given in one line, which are: the value calculated after the ratio of the density of large celestial bodies to the density of small celestial bodies is opened to the third power (≤ 1), the attribute of small celestial bodies (0 represents fluid and 1 represents rigid body), and the ratio of the distance between two celestial bodies to the radius of large celestial bodies (> 1 but not more than 10).

Output format:
In one line, first output the ratio of the Roche limit of small objects to the radius of large objects (2 decimal places); Then empty one space; Final output_ If the small object will not be torn, otherwise output T_T.

Input example 1:
0.622 0 1.4
No blank lines at the end

Output example 1:
1.53 T_T
No blank lines at the end

Input example 2:
0.622 1 1.4
No blank lines at the end

Output example 2:
0.78 _
No blank lines at the end

```#include<iostream>
using namespace std;

int main() {
double a,c;
int b;
double x,y;
cin>>a>>b>>c;
if(b==0)
x=2.455*a;
else if(b==1)
x=1.26*a;
if(x<c)
printf("%.2f ^_^",x);
else
printf("%.2f T_T",x);
return 0;
}

```

# L1-068 harmonic average (10 points)

The arithmetic mean of n positive numbers is the sum of these numbers divided by N, and their harmonic mean is the reciprocal of the arithmetic mean of their reciprocal. Please calculate the harmonic average of a given series of positive numbers.

Input format:
Each input contains 1 test case. The first line of each test case gives a positive integer N (≤ 1000); Line 2 gives N positive numbers, all within the interval [0.1100].

Output format:
Output the harmonic average value of a given sequence in one row, and output 2 digits after the decimal point.

Input example:
8
10 15 12.7 0.3 4 13 1 15.6
No blank lines at the end

Output example:
1.61
No blank lines at the end

```#include<bits/stdc++.h>
using namespace std;

int main()
{
int n;
double x,sum=0;
cin>>n;
int t=n;
while(n--)
{
cin>>x;
sum+=1.0/x;
}
printf("%.2f",t/sum);
}
```

# L1-069 tire pressure monitoring (15 points)

There is a system in the car to monitor the tire pressure of the four wheels at any time. If the tire pressure of the four wheels is not very balanced, it may have a serious impact on the driving.

taiya.JPG

Let's number the four wheels - left front wheel, right front wheel, right rear wheel and left rear wheel - as 1, 2, 3 and 4. In this topic, please write a monitoring program to monitor the tire pressure of four wheels at any time and give correct alarm information. The alarm rules are as follows:

If the error between the pressure values of all tires and their maximum values is within a given threshold and is not lower than the minimum alarm tire pressure set by the system, it indicates that the situation is normal and there is no alarm;
If the error between the pressure value of a tire and the maximum value exceeds the threshold, or is lower than the minimum alarm tire pressure set by the system, not only the alarm shall be given, but also the accurate position of the tire that may leak shall be given;
If the pressure value of two or more tires exceeds the threshold value or is lower than the minimum alarm tire pressure set by the system, the alarm requires all tires to be checked.
Input format:
Enter 6 integers in the range of [0, 400] in one line, which are the tire pressure of No. 1 ~ 4 tires, the lowest alarm tire pressure, and the threshold of tire pressure difference.

Output format:
The corresponding information is given according to the entered tire pressure value:

If there is no alarm, output Normal;
If a tire needs to give an alarm, it will output Warning: please check #X!, Where X is the number of the tyre in question;
If you need to check all the tires, output Warning: please check all the tires!.

Input example 1:
242 251 231 248 230 20
No blank lines at the end

Output example 1:
Normal
No blank lines at the end

Input example 2:
242 251 232 248 230 10
No blank lines at the end

Output example 2:
No blank lines at the end

Input example 3:
240 251 232 248 240 10
No blank lines at the end

Output example 3:
Warning: please check all the tires!
No blank lines at the end

```//A test point error
/*#include<bits/stdc++.h>
using namespace std;

int main()
{
int a,c=0,t,x,b=-1;

for(int i=1;i<=6;i++)
{
cin>>a[i];
b=max(b,a[i]);
}

if((a<a)||(fabs(a-b)>a))
{
c++;
if(c==1)t=1;
}
else if((a<a)||(fabs(a-b)>a))
{
c++;
if(c==1)t=2;
}
else if((a<a)||(fabs(a-b)>a))
{
c++;
if(c==1)t=3;
}
else if((a<a)||(fabs(a-b)>a))
{
c++;
if(c==1)t=4;
}
if(c==0)printf("Normal\n");
else printf("Warning: please check all the tires!\n");
return 0;
} */

#include<bits/stdc++.h>
using namespace std;
int main()
{
int a, bj, yz;
int mx=-1;

for(int i=1;i<=4;i++){cin>>a[i];mx=max(mx,a[i]);}
cin>>bj>>yz;
int ok = 1, lq;

for(int i = 1; i <= 4; i++)
{
if(mx-a[i]>yz || a[i]<bj)
{
if(ok==1)ok=0;//Set up once 0
else ok = 2;  //Set up many times 2
lq = i;//Set up once and record the tire; It has been established for many times without any effect
}
}

if(ok==1)cout<<"Normal\n";                                      //0
else if(ok==0)cout<<"Warning: please check #"<<lq<<"!\n";       //1
else cout<<"Warning: please check all the tires!\n";            //2,3,4
return 0;
}

```

# L1-070 eating hot pot (15 points)

chg.jpg

The above picture comes from wechat circle of friends: it's basically useless to call me if you have something bad in this weather. But if you say "eat hot pot", it's great, and our story begins.

This topic requires you to implement a program to automatically check whether there is chi1 huo3 guo1 in the information sent to you by your friends.

Input format:
Enter a friend information with no more than 80 characters and ending with carriage return in each line. The information is a non empty string, including only letters, numbers, spaces and visible half width punctuation. When you read that there is only one English period in a line, the input ends. This line is not included in the friend information.

Output format:
First, output the total number of friend information in one line. Then check whether each line of information of friends contains chi1 huo3 guo1, and count the number of such powerful information. In the second line, first output the information of chi1 huo3 guo1 for the first time (counting from 1), and then output the total number of such information, separated by a space. The title ensures that all numbers output do not exceed 100.

If your friend doesn't mention the keyword chi1 huo3 guo1 from beginning to end, output an expression on the second line -#.

Input example 1:
Hello!
are you there?
wantta chi1 huo3 guo1?
that's so li hai le
our story begins from chi1 huo3 guo1 le
.
No blank lines at the end

Output example 1:
5
3 2
No blank lines at the end

Input example 2:
Hello!
are you there?
wantta qi huo3 guo1 chi1huo3guo1?
that's so li hai le
our story begins from ci1 huo4 guo2 le
.
No blank lines at the end

Output example 2:
5
-_-#
No blank lines at the end

```#include<bits/stdc++.h>
using namespace std;
int main()
{
//i defines the total number of statements, n defines how many times "eat hot pot" appears, t defines what information "eat hot pot" appears for the first time, and flog records whether there is this string
int n=0,i=0,t=0,flog=0;
string s;

while(getline(cin,s)&&s!=".")
{
i++;
if(s.find("chi1 huo3 guo1")!=-1)
{
flog=1;
if(n==0)t=i;
n++;
}
}

if(flog==1)
{
printf("%d\n",i);
printf("%d %d\n",t,n);
}
else
{
printf("%d\n",i);
printf("-_-#\n");
}
}

/*#include<bits/stdc++.h>
using namespace std;
int main()
{
//a Define the total number of statements, b define how many times "eat hot pot" appears, and c define what information "eat hot pot" appears for the first time.
int a=0,b=0,c;
string s;

while(getline(cin,s)&&s!=".")
//Read in line by line, and judge whether you can continue to read in
{
a++;
if(s.find("chi1 huo3 guo1")!=-1)
{
if(!b) c=a;

b++;
}
}
cout<<a<<endl;
if(b)
cout<<c<<" "<<b<<endl;
else
cout<<"-_-#"<<endl;
return 0;
}
*/
```

Posted by mikeissa on Sat, 02 Oct 2021 17:56:49 -0700