# 2016CCPC杭州站 F - Four Operations 【枚举】

50 篇文章 0 订阅

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).

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

a+b-c*d/e

c和d为个位数。
a与b中有一个个位数。

#include<iostream>
#include<string.h>
#include<stdio.h>
#include<math.h>
using namespace std;
#define LL long long
int T;
char s[25];
int main()
{
scanf("%d",&T);
LL cas = 0;
while(T--){
scanf("%s",s);
LL len = strlen(s);
LL mx = -1e16;
LL p[25]={1};
for(int i=1;i<=16;i++) p[i] = p[i-1]*10;
for(int i=3;i<len-1;i++){
LL ans ;
LL c = s[i-1] -'0';
LL d = s[i] - '0';
LL a1=0,b1=0,e=0,a2 = 0,b2=0;
for(int j=len-1;j>i;j--){
e+=(s[j]-'0')*p[len-1-j];
}
a1 = s[0] - '0';
b2 = s[i-2] -'0';
for(int j=i-2;j>=1;j--){
b1 += (s[j]-'0')*p[i-2-j];
}
for(int j=i-3;j>=0;j--){
a2 += (s[j]-'0')*p[i-3-j];
}
ans = max(a1+b1-c*d/e,a2+b2-c*d/e);
mx = max(mx,ans);
}
printf("Case #%lld: %lld\n",++cas,mx);
}
return 0;
}

• 0
点赞
• 0
收藏
觉得还不错? 一键收藏
• 0
评论
10-31 777
10-29 721
10-29 961
10-30 405
04-09 104
11-08 144
08-24 284

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。