Connection Status:
Competition Arena > ForgetfulAddition
SRM 642 · 2014-08-25 · by lg5293 · Brute Force
Class Name: ForgetfulAddition
Return Type: int
Method Name: minNumber
Arg Types: (string)
Problem Statement

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 String expression that contains the expression on Alice's screen. Compute and return the smallest possible result after inserting the missing plus sign

Constraints

  • expression will contain between 2 and 8 characters, inclusive.
  • Each character of expression will be between '1' and '9'.
Examples
0)
"22"
Returns: 4

The only possible expression Alice could have typed is "2+2". Thus, Bob knows this evaluates to 4.

1)
"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.

2)
"1289"
Returns: 101

This is the example from the problem statement.

3)
"31415926"
Returns: 9067
4)
"98765"
Returns: 863

Submissions are judged against all 58 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

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

Submitting as anonymous