2023 Huawei od unified exam B paper [string division] C language implementation

Table of contents  

topic

train of thought

Code


topic

Given a string S composed of lowercase letters, please find two characters in different positions in the string as split points, so that the string is divided into three consecutive substrings with equal weights. Note that the substrings do not contain split points.
If two split points satisfying the conditions can be found, please output the subscripts of the positions of the two split points in the string. If no split points satisfying the conditions can be found, please return "0,0". The calculation method of the substring weight is: the sum of the ASCII code values ​​of all characters in the substring.
Input description
The input is a string consisting of a~z, 26 lowercase letters, 5< S.length < 200.
Output description
The output is the subscript of the position of the two split points in the string, separated by commas Remarks
Only
the unique solution is considered, and there is no case where one input has multiple output solutions

Example 1:

input
acdbbbca
output

2,5
Explanation
Use positions 2 and 5 as the splitting points to split the string into three substrings ac, bb, and ca. The weight of each substring is 196, and the output is: 2,5

Example 2:

enter:

abcabc

Guess you like

Origin blog.csdn.net/misayaaaaa/article/details/132618708