Little 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 into 55 intervals and add the four operations ‘+’, ‘-’, ‘*’ and ‘/’ in order, then calculate the result(/ used as integer division).
Now please help him to get the largest result.
Input
First line contains an integer TT, which indicates the number of test cases.
Every test contains one line with a string only contains digits ‘1’- ‘9’.
Limits
1≤T≤1051≤T≤105
5≤length of string≤205≤length of string≤20
Output
For every test case, you should output ‘Case #x: y’, where x indicates the case number and counts from 1 and y is the result.
Sample Input
1
12345
Sample Output
Case #1: 1
#include<iostream>
#include<stdio.h>
#include<stack>
#include<algorithm>
#include<string.h>
#include<queue>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long LL;
long long a[1000];
long long sum(int x,int y){
long long tans=0;
int i;
for(i=x;i<=y;i++) tans=tans*10+a[i];
return tans;
}
int main(){
int t;
scanf("%d",&t);
int cnt=1;
while(t--){
printf("Case #%d: ",cnt++);
string s;
cin>>s;
int n=s.size();
for(int i=0;i<n;i++) a[i]=s[i]-'0';
LL ans=0;
ans+=sum(1,n-4);
ans+=a[0];
ans-=(a[n-3]*a[n-2])/a[n-1];
LL ans1=0;
ans1+=sum(0,n-5);
ans1+=a[n-4];
ans1-=(a[n-3]*a[n-2])/a[n-1];
ans=max(ans,ans1);
if(n>5){
ans1=0;
ans1+=sum(0,n-6);
ans1+=a[n-5];
ans1-=(a[n-4]*a[n-3])/(sum(n-2,n-1));
ans=max(ans,ans1);
ans1=0;
ans1+=sum(1,n-6);
ans1+=a[0];
ans1-=(a[n-4]*a[n-3])/(sum(n-2,n-1));
ans=max(ans,ans1);
}
printf("%lld\n",ans);
}
}