[Java] Solve At Coder Beginner Contest 175 in java

2 minute read

AtCoder Beginner Contest 175 Thank you for your hard work! Official page

The code I wrote this time is here The result was AC from AC. Both D and E were difficult…

Below is a brief explanation.

Problem A

The question to answer how many times the string is continuous. String.charAt() I got the specified character with, and frankly wrote the condition document.

Problem B

The problem of outputting whether or not it becomes a triangle given the length of three sides. Note that edges with the same length should not be used.

You don’t have to worry about the amount of calculation, and even a triple loop will be enough. Inside the triple loop looks like this. First of all, I checked if there is any one with the same side length, and judged if it was a triangle.

if (first == second || second == third || third == first) {
if (isTriangle(first, second, third)) {

The judgment as to whether it is a triangle or not is performed as follows.

public static boolean isTriangle(int i, int j, int k) {
int max = Math.max(i, j);
max = Math.max(max, k);
return i + j + k-max> max;

Problem C

The problem is to move the X times K times on the number line D times and output the position closest to the origin. A little drawing, when K and D are smaller than X, just move towards the origin, If not, you can see that the value depends on whether it is an even number or an odd number.

If K or D is larger than X to some extent, it is an image of wandering around the origin.

Also, since X, K, and D are all large, the point is not to use multiplication unnecessarily. (It will overflow.) First, we can write the branch when X is large enough.

if (x / d> k) {
print(x-d * k);

If not, let’s distinguish x%d or d-x%d by even and odd and output it. Also note that X can be negative. It took a lot of time…

Problem D

(Postscript later)

Problem E

(Postscript later)


It was the lowest performance (592), because I overslept for 20 minutes, Rating also dropped 4 times in a row, orz to 930

Review the D and E problems thoroughly, update them at a later date and write the source code…! Hey!

Thank you for reading to the end!