Connection Status:
Competition Arena > Conglutination
SRM 246 · 2005-06-09 · by Andrew_Lazarev · Brute Force, Simple Math, String Manipulation
Class Name: Conglutination
Return Type: String
Method Name: split
Arg Types: (string, int)
Problem Statement

Problem Statement

You are developing a new software calculator. Some people use the calculator to check the sums of several numbers, but they sometimes get unexpected results because they forget to press the 'plus' button. You have almost solved this problem, but a small method is still required.

You will be given a String conglutination and an int expectation. Your method should split conglutination into two numbers A and B so that A + B = expectation. Return the result as a String in the form "A+B" (quotes for clarity only). A and B must contain at least one digit each. Leading zeros are allowed and they must be preserved in the result. If there are several possible splits, choose the one with the smallest value of A. Return an empty String if there are no possible splits.

Constraints

  • conglutination will contain between 2 and 20 characters, inclusive.
  • conglutination will contain only digits ('0'-'9').
  • The first character of conglutination will not be zero.
  • expectation will be between 1 and 1000000000, inclusive.
Examples
0)
"22"
4
Returns: "2+2"
1)
"536"
41
Returns: "5+36"
2)
"123456000789"
1235349
Returns: "1234560+00789"

Be careful with leading zeros.

3)
"123456789"
4245
Returns: ""
4)
"112"
13
Returns: "1+12"

The value of A should be as small as possible.

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

Coding Area

Language: C++17 · define a public class Conglutination with a public method string split(string conglutination, int expectation) · 87 test cases · 2 s / 256 MB per case

Submitting as anonymous