ForgetfulAddition
SRM 642 · 2014-08-25 · by lg5293
Problem Statement
Alice had two positive integers, a and b. She typed the expression "a+b" into her computer, but the '+' key malfunctioned. For example, instead of "128+9" the computer's screen now shows "1289".
Later, Bob saw the string on the screen. He knows that the '+' sign is missing but he does not know where it belongs. He now wonders what is the smallest possible result of Alice's original expression.
For example, if Bob sees the string "1289", Alice's expression is either "128+9" or "12+89" or "1+289". These expressions evaluate to 137, 101, and 290. The smallest of those three results is 101.
You are given a
Constraints
- expression will contain between 2 and 8 characters, inclusive.
- Each character of expression will be between '1' and '9'.
"22" Returns: 4
The only possible expression Alice could have typed is "2+2". Thus, Bob knows this evaluates to 4.
"123" Returns: 15
The expression Alice has typed could have been "1+23" or "12+3". Of these two, the second is smaller, thus Bob will get the answer 15.
"1289" Returns: 101
This is the example from the problem statement.
"31415926" Returns: 9067
"98765" Returns: 863
Submissions are judged against all 58 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class ForgetfulAddition with a public method int minNumber(string expression) · 58 test cases · 2 s / 256 MB per case