The tenth question of Java Blue Bridge Cup 16 years

Java password falls off

Archaeologists on Planet X have discovered a collection of ancient codes.
These codes are sequences strung together from the seeds of four plants, A, B, C, and D.
After careful analysis, it is found that these password strings should be symmetrical before and after (that is, what we call mirror strings).
Many of these seeds have fallen off due to age, and thus may lose their mirror-image characteristics.

Your task is:
given a password string you see now, calculate how many seeds it needs to drop from its original state before it can become what it is now.

Enter a line, indicating that the password string (length not greater than 1000) seen now
requires a positive integer to indicate at least how many seeds have been dropped.

For example, input:
ABCBA
then the program should output:
0

For another example, input:
ABDCDCBABC
the program should output:
3

Resource convention:
peak memory consumption (including virtual machine) < 256M
CPU consumption < 3000ms

Please output strictly according to the requirements, and do not superficially print superfluous content like: "Please enter...".

All code is placed in the same source file, after debugging, copy and submit the source code.
Note: Do not use the package statement. Do not use features of jdk1.7 and above.
Note: The name of the main class must be: Main, otherwise it will be processed as invalid code.

The idea is to find the middle value and then compare the two sides in turn. If they are the same, continue to look for the two sides. If they are different, there are two cases. One is to add the value on the right to the left, and the other is opposite, and then judge. . .

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324573061&siteId=291194637