A-robot bicorn attack

Source: Internet
Author: User

Description

Vasya plays robot bicorn attack.

The game consists of three rounds. for each one a non-negative integer amount of points is given. the result of the game is the sum of obtained points. vasya has already played three rounds and wrote obtained points one by one (without leading zeros) into the stringS. Vasya decided to brag about his achievement to the friends. However, he has forgotten how many points he got for each round. The only thing he remembers is the stringS.

Help Vasya to find out what is the maximum amount of points he cocould get. Take into account that Vasya played robot bicorn attack for the first time, so he cocould not get more than 1000000 (106) points for one round.

Input

The only line of input contains non-empty stringSObtained by Vasya. The string consists of digits only. the string length does not exceed 30 characters.

Output

Print the only number-the maximum amount of points Vasya cocould get. If Vasya is wrong and the string cocould not be obtained according to the rules then output number-1.

Sample Input

Input
1234
Output
37
Input
9000
Output
90
Input
0009
Output
-1

 1 #include <stdio.h> 2 #include <string.h> 3 #define LL __int64 4  5 int main() 6 { 7     int i,j,k,n,a,b,c,max,l,flag=0; 8     char s[32]; 9     gets(s);10     max=a=0;11     n=strlen(s);12     for(i=0;i<n-2;i++)13     {14         a=a*10+s[i]-‘0‘;15         if(a>1000000)break;16         b=0;17         for(j=i+1;j<n-1;j++)18         {19             b=b*10+s[j]-‘0‘;20             if(b>1000000)break;21             l=c=0;22             for(k=j+1;k<n;k++)23             {24                 c=c*10+s[k]-‘0‘;25                 if(c>1000000)break;26                 if(c==0&&s[k]==‘0‘&&k!=n-1)27                     break;28             }29             if(k==n&&c<=1000000)l=flag=1;30             if(l)31             {32                 if(max<a+b+c)max=a+b+c;33     //            printf("%d %d %d\n",a,b,c);34             }35             if(b==0&&s[j]==‘0‘)break;36         }37         if(a==0&&s[i]==‘0‘)break;38     }39     if(flag)printf("%d\n",max);40     else puts("-1");41     return 0;42 }

 

A-robot bicorn attack

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.