From this time, I will solve the problem in AtCoder and regularly check the contents of the problem I'll post a commentary: relaxed:
I don't know how many times it will last or if there is demand, but someone I hope it helps you when you get stuck: kissing_smiling_eyes:
Then, I would like to continue loosely from this time, so thank you: grin:
I tried to solve 3 questions this time! Now let's explain and explain the problem: stuck_out_tongue_winking_eye: 「9x9」
Takahashi remembered multiplication tables, so he could calculate the product of two integers from 1 to 9 I can do it. No other calculation is possible. Two integers A and B are given. If Takahashi can calculate A × B, the result, if not, -1 instead Please output.
1 ≤ A ≤ 20 1 ≤ B ≤ 20 All values being entered are integers.
Input is given from standard input in the following format. A,B
If Takahashi can calculate A x B, output the result, and if not, output -1.
It was a problem. My answer is ↓.
9x9.py
A , B = map(int, input().split())
if 1 <= A and A <= 9 and 1 <= B and B <= 9:
print(A * B)
else:
print(-1)
I'll explain it easily: wink:
First, make two variables in the form of "variable, variable = map (type, input (). Split ())" Input from standard input. Use ".split ()" to separate with spaces You can divide the entered character string and enter it. By the way, ".sprit (" and ")" If you enter it like this, it will be separated by the characters "and": grin:
Then use "if" and "and" to create multiple conditions and if they apply Use "print" to print the result of multiplication of A and B. If the conditions are not met, "-1" is output.
that's all! It's easy: stuck_out_tongue_winking_eye: Let's go next: laughing:
「Curtain」
The horizontal length of the window of Takahashi-kun's house is A, and the horizontal length is B. Two curtains are attached. (The curtain is vertical It is long enough to cover the window. )
Minimize the lateral length of the part of the window that is not hidden by the curtain Close the curtain so that it becomes. At this time, it is hidden by the window curtain Find the total lateral length of the missing parts.
1 ≤ A ≤ 100 1 ≤ B ≤ 100 A and B are integers.
Input is given from standard input in the following format. A , B
Output the total lateral length of the part of the window that is not hidden by the curtain. Output 0 if the window is completely covered by curtains. Each curtain may be longer than the width of the window.
It was a problem. My answer is ↓.
Curtain.py
A , B = map( int, input().split())
if(A - (B * 2) <= 0):
print(0)
else:
print(A - (B * 2))
This is first divided into two variables in the form of "variable, variable = map (type, input (). Split ())" Input from standard input. Since it is "split ()", it is input as a space delimiter: point_up: Next, use the "if (condition)" statement to determine whether the curtain will hide or not hide the window. "0" if hidden, non-hidden horizontal length "A-(B * 2)" if not hidden With a "print ()" statement.
that's all. This is also easy: grin: Next is the last of this time! 「Tenki」
A three-day weather forecast is given as a string S of length 3.
When the i (1 ≤ i ≤ 3) letter of S is S, the weather forecast for day i was clear. A C means it was cloudy, and an R means it was raining. Also, the actual weather for 3 days is given as a string T of length 3. When the i (1 ≤ i ≤ 3) letter of T is S, the actual weather on day i was sunny, A C means it was cloudy, and an R means it was raining. Please output how many days the weather forecast hit in 3 days.
S and T are strings of length 3. S and T consist only of S, C, R.
Input is given from standard input in the following format. S , T
Output how many days the weather forecast hit in 3 days.
It was a problem. My answer is ↓.
Tenki.py
S = list(input())
T = list(input())
i = 0
x = 0
while(i < 3):
if(S[i] == T[i]):
x = x + 1
i = i + 1
print(x)
In this problem, first input a string to S and T from standard input with "list (input ())" I was allowed to. Next, the variable "i" is used to compare the characters three times, and the variable "x" is used to compare and count the number of matches. I prepared it. After that, set the condition to "i <1" in the "while (condition)" statement and set "i = i + 1" each time the process is completed. By doing this, the process is repeated 3 times, and the contents of the S [] and T [] arrays are compared in order and match. Process "x = x + 1". After exiting while, you can display the number of matches by displaying x with "print ()". Done: relaxed:
This time I tried to solve three simple problems. To be honest, I think it was too easy for someone who understands programming: joy: I'm going to write loosely like this, so there are things that are difficult to understand and useless writing I would be grateful if you could let me know in the comments, which would be good for my study: blush: Up to here for this time! : blush :: joy :: kissing:
Recommended Posts