In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of java how to achieve the brick game, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this java article on how to achieve the brick game. Let's take a look at it.
A brick game algorithm, for your reference, the specific content is as follows
Here is a brick game: there are many bricks in front of Xiao Ming, each brick has a character, each hit a brick, will produce a score, and the total score is the sum of these scores. The characters on the brick can be numbers, symbols, or letters, and the rules for each character are as follows:
If there is a number on the brick hit, the score is the value of the number.
If the brick hit is' Downs', the score is twice as high as the previous one.
If the brick hit is'+', the score is the sum of the first two scores.
If the brick hit is' Cruise', the previous score will be cancelled, and the previous score will not be counted in subsequent statistics.
Write an algorithm to calculate the total score for Xiaoming's game process.
Request
Enter as two parameters, one called blocks, which represents a list of characters, and the other called n, which represents the number of characters in the list.
The output is an integer that represents the total score calculated for a given list.
Examples
The input is:
Blocks = [5,-2, 4, C, D, 9, +], n = 8
Output as
twenty-seven
The calculation process is as follows:
Hit the number 5 for the first time, score 5 points, total score 5 points
The second time hit the number-2, score-2, total score 5-2 = 3
Hit the number 4 for the third time, score 4 points, total score 3 + 4 = 7 points
Hit the letter C for the fourth time, the last score was invalidated, and the total score returned to the 3 points of the second time.
Hit the letter D for the fifth time, take the last score of-2, multiplied by 2, that is-4, the total score is-1. Note that the previous C canceled the third score and did not count it, so the second score before it was taken as the last score.
Hit the number 9 for the sixth time and get 9 points, with a total score of-1 + 9 = 8
Hit the symbol + for the seventh time, get 9-4 = 5, and the total score is 8 + 5 = 13.
Hit the symbol + for the eighth time, with a score of 5 + 9 = 14 and a total score of 14 + 13 = 27
Calculate the total score of 27 points.
The analysis process is brief, go directly to the code:
Import java.util.*;import java.util.regex.Matcher;import java.util.regex.Pattern;public class Solution {public static int totalScore (String [] blocks, int n) {if (n)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 265
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.