Program design and practice second question & ideas (no code) (T7 has been completed)

\ DO NOT GET / \ DO NOT GET / \ DO NOT GET /
V1.0.1Question 7 has been filled
Insert picture description here
Image transfer


There is a saying that this week’s questions are so difficult, but I didn’t start writing the solution until noon on Saturday, and I made 1 QAQ on Thursday.

T6 change composition

Description

Xiao Zhang's English is not very good, and today he is facing the trouble of English composition again.
Finally he finished his composition one second before the ddl, but due to the rush, the capitalization of many words appeared problems.

Please help him to finish the English composition in one second!

Ideas

Insert picture description here

"Thousand Characters" published overnight

Description

Please write a program to read a Chinese article from the input, and count the number of repeated occurrences of each word other than ASCII characters in the article.

The article uses UTF-8 encoding, and any characters that can be represented by UTF-8 encoding may appear (not limited to Chinese).

All the characters in the article are within the range that UCS-2 can represent, that is, the Unicode value of the character can be represented by two bytes.

Ideas

Insert picture description here
Insert picture description here

T8 cycle section

Description

Xiao Zhang is a person who likes rules, so he has a lot of research on the cycle of numbers.

For example, the number 123123123 has a loop section with a length of 3 and 9.

The number 12341234 has a cyclic section of length 4 or 8.

The number 12345, there is only a loop with a length of 5.

Now Xiao Zhang gives you a number A. Please help him find the smallest number greater than A and with a loop length of L.

Ideas

Suppose the length of the loop section is L, and the length of the number A is len.

Because this question seems to be complicated to do with numbers like 99999, I simply took out the list with 9 in each position and judged it:
如果全是9:
if L = 1, 111111 is done.
If L is not 1, then 1000010000.
一般情况:
If L> len, 100000000 is done.
If L = len, perform something like high-precision addition +1, and calculate the one that is greater than A by 1 and it will be done.
If L <len, we need to determine whether L is a factor of len:
if not , Or 10001000.
If yes, take out the first L digits of A, and then compare L digits each time. If one bit is found to be bigger, just output it directly, if one bit is found to be smaller, you need to perform similar high precision Add +1 to the same thing until it gets bigger.
Note that this question must be strictly greater than or equal to
Finally, attach a few cases of mistakes made during debugging.
If you have 7,16WA, please test 999998, which should output 999999 or several 999.
If you have 11,14 WA, please test 3. 123124122 should output 124124124 instead of 123123123.
If you have 6,15WA, please test. 3 1 This should output 100 instead of 111. When
I first submitted it, I had these 6 WAs. Later I adjusted them a little bit. As for other use cases, I am really not sure.

T9 gift

Description

Xiao Zhang's good friend Komatsu is celebrating his birthday, and Xiao Zhang plans to choose a gift for him. In the market he found that there was a nice shop with bead bracelets. In this store, special beads are sold and worn as a bracelet. The beads are arranged in a row on the shelf, and each bead has a lowercase English letter. The store has a special rule that the beads must be selected in order from left to right in a row. Xiao Zhang already has a word he wants to give to Komatsu. Please tell him how to choose the beads so that the letters of the beads on the bracelet form the words Xiao Zhang wants.

Ideas

I think some classmates have been tortured for a long time for this question. Then I listened to HAACHAMA’s song and wrote it again. It was amazing after it was time to buy a lottery ticket. The
first bead on the shelf I read is called tmp, and the length of tmp = Len, the word I want is called aim, and I take a his array to record the subscript of the beads.
My idea for this question is to double the tmp, and repeat the new string store = tmp.
Then start to match aim from the first place of the store. If found, his first write down the subscript i of this place, and then continue to traverse the store from this place to i+len, because if it continues, it will string Drop. If the aim is all matched, the output is fine.
The limitation of this question is that the subscript of the newly found store match is either the largest in his, or it is smaller than the first match after %len, or this one will be inserted If you go in the middle, you can't "string into a ring".
(It’s a bit convoluted, I don’t think I’ve made it clear myself)

T10 bracket matching

Description

DarkDown came up with a given sequence of parentheses in music to determine its legality.

The bracket sequence is a non-empty sequence composed of the left bracket "(" and the right bracket ")". It is easy to determine the validity of a bracket sequence. For example, "()", "(())()", "(()())", "(()(()))", "()()()" are all legal, while " )", "(", "(()", "(()))(" are all illegal.

Roark glanced at the question and immediately went to the drinking fountain to pick up a glass of water.

DarkDown realized that he was suggesting that the question was too watery, so he immediately changed the question, adding one, and one more difficulty.

Given n bracket sequences, pair them in pairs, and ask how many pairs of legal bracket sequences can be formed. (Each bracket sequence can only appear in a pair)

Roark came back after receiving the water and looked at the new question, and started scratching his head. Help him!

Ideas

Because in this topic description, the convenient way to judge the legitimacy of parentheses is to use the stack, so I will probably use the stack first.
In the beginning, my idea was to grab two of them and put them together, and then judge whether the match did not match.
When judging the match, I did the same. Only the left parenthesis was put on the stack. If a right parenthesis was entered and the stack was empty, it would explode.
However, this method must be TLE, because I didn't want to understand why the second use case is 1, and I feel that the order of the two exchanges is different, why is it 1.
Then DF told me what this sentence means: Insert picture description here
If it is matched, it is thrown away and will not continue to participate in the match.
But because the brackets are similar to binary, because there are only left and right, there will be “A跟B,C能匹配,B跟C,D能匹配,C不能匹配D,但是由于我先把AB组合导致原来能匹配两组现在只能匹配一组”no situation.
So the later idea is probably this:
first simplify each input bracket sequence, remove the middle of the original can match. Brackets, there are only four cases left:

  1. All left parenthesis
  2. All right parentheses
  3. Left and right
  4. Nothing left (self-matching)

For 3, because this question can only grab two randomly to match, so as long as it is 3, just throw it away and let him crawl.
For 4, 4 this must not match 1, 2, so the final result is just added 4这种情况出现的次数/2.
For 1, 2 because there must be only the same number of left (right) parentheses to match, so for each case of the same number of left (right) parentheses, take their minimum value.
For example:
if "((" has 5, "))" there are 3, then the final result +min(5,3) = 3.

Thanks

QWQThank you DF and LHL for their supportQWQ

At last

I feel that there are still a lot of views on the solution of the first topic before... My classmates are really good at learning XD.
If you have any questions or opinions, please leave a message in the comment area, thank you.
(But don't directly post the code and ask for debug) The
T7 principle pit ideas and so on will be added soon.
Question 7 has been filled
(I know 8 too much myself, I
have been tossing for a long time ) I hope I can do a little better QWQ next time

Guess you like

Origin blog.csdn.net/Leo9344/article/details/108547800