2016 Chinese university student Program Design Competition (Hangzhou) 1006 Four Operations

Source: Internet
Author: User
Tags integer division

Four Operations

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): Accepted submission (s): 18


Problem Descriptionlittle Ruins is a studious boy, recently he learned the four operations!

Now he want to use four operations to generate a number, he takes a string which only contains digits ' 1 '- ' 9 ', and split it into5 intervals and add the four operations ' + ', '-', ' * ' and '/' on order, then Calculate the result (/used as Integer division).

Now you are him to get the largest result.

Inputfirst line contains an integerT, which indicates the number of test cases.

Every test contains one line with a string of only contains digits ' 1 '- ' 9 '.

Limits
< Span id= "mathjax-span-8" class= "Mrow" >1 ≤t ≤ 105
5 ≤length of String≤20

Outputfor every test case, should output ' case #x: Y ', where xIndicates the case number and counts from 1and yis the result.

Sample Input112345

Sample outputcase #1:1

Source 2016 China University student Program Design Competition (Hangzhou)

Recommendliuyiding
/*enumeration minus, just beginning naïve thought, the divisor is two bits maximum ... Stuck dead. */#include<bits/stdc++.h>#definell Long Long#defineINF 0X3FFFFFFFFFFFFFFF#defineN 22using namespacestd;stringOp;ll Right (strings) {ll e=0; intn=s.size ();  for(intI=2; i<n;i++) e=e*Ten+s[i]-'0'; //cout<<c<< "" <<d<< "" <<e<<endl;ll ans= (s[0]-'0') * (s[1]-'0')/e; returnans;} ll left (stringS//the left part of the minus sign{ll Cur1=0, cur2=0; intn=s.size ();  for(intI=1; i<n;i++) Cur1=cur1*Ten+ (s[i]-'0'); Cur1+=s[0]-'0';  for(intI=0; i<n-1; i++) Cur2=cur2*Ten+ (s[i]-'0'); CUR2+=s[n-1]-'0'; //cout<< "Max (CUR1,CUR2) =" <<max (CUR1,CUR2) << "";    returnMax (CUR1,CUR2);} ll solve (strings) {    ///enumeration minus signll cur=-inf,s1,s2; intn=s.size ();  for(intI=2; i<=n-3; i++) {S1=left (S.substr (0, i)); S2=right (S.substr (i,n-i)); //cout<<s1<< "" <<s2<<endl;Cur=max (cur,s1-S2); } printf ("%lld\n", cur);}intT;intMain () {//freopen ("C:\\users\\acer\\desktop\\in.txt", "R", stdin);scanf"%d",&t);  for(intCase=1; case<=t; case++) {printf ("Case #%d:", case); CIN>>op;    Solve (OP); }    return 0;}

2016 Chinese university student Program Design Competition (Hangzhou) 1006 Four Operations

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.