Programming contests

ECN selejtező programozó csapatverseny, 2013. április 28.

April 28, 2013 10:15 AM – April 28, 2013 3:15 PM

String Partition

John was absurdly busy for preparing a programming contest recently. He wanted to create a ridiculously easy problem for the contest. His problem was not only easy but also boring: Given a list of nonnegative integers, what is the sum of them?

However, he made a very typical mistake when he wrote a program to generate the input data for his problem. He forgot to print out spaces to separate the list of integers. John quickly realized his mistake after looking at the generated input file because each line was simply a string of digits instead of a list of integers.

He then got a better idea to make his problem a little more interesting: There are many ways to split a string of digits into a list of non-zero-leading (0 itself is allowed) 32-bit signed integers. What is the maximum sum of the resultant integers if the string is split appropriately?

Input Specification

The input begins with an integer N (N ≤ 500), which indicates the number of test cases followed. Each of the following test cases consists of a string of at most 200 digits in a line by itself.

Output Specification

For each input, print out the required answer in a single line.

Sample Input

  1. 6
  2. 1234554321
  3. 5432112345
  4. 000
  5. 121212121212
  6. 2147483648
  7. 11111111111111111111111111111111111111111111111111111
download as text file

Output for Sample Input

  1. 1234554321
  2. 543211239
  3. 0
  4. 2121212124
  5. 214748372
  6. 5555555666
download as text file
University of Debrecen; Faculty of Informatics; v. 03/01/2019