Four Operations

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 38    Accepted Submission(s): 18

Problem Description
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 5

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 T

, which indicates the number of test cases.

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

Limits
1≤T≤105

5≤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
 
Source
 
Recommend
liuyiding

/*
枚举减号,刚开始天真的以为,除数最多是两位......卡死。
*/
#include<bits/stdc++.h>
#define ll long long
#define INF 0x3fffffffffffffff
#define N 22
using namespace std; string op; ll right(string s)
{
ll e=;
int n=s.size();
for(int i=;i<n;i++)
e=e*+s[i]-'';
//cout<<c<<" "<<d<<" "<<e<<endl;
ll ans=(s[]-'')*(s[]-'')/e;
return ans;
} ll left(string s)//减号左边的部分
{
ll cur1=,cur2=;
int n=s.size();
for(int i=;i<n;i++)
cur1=cur1*+(s[i]-'');
cur1+=s[]-'';
for(int i=;i<n-;i++)
cur2=cur2*+(s[i]-'');
cur2+=s[n-]-'';
//cout<<"max(cur1,cur2)="<<max(cur1,cur2)<<" ";
return max(cur1,cur2);
}
ll solve(string s)
{
///枚举减号
ll cur=-INF,s1,s2;
int n=s.size();
for(int i=;i<=n-;i++)
{
s1=left(s.substr(,i));
s2=right(s.substr(i,n-i));
//cout<<s1<<" "<<s2<<endl;
cur=max(cur,s1-s2);
}
printf("%lld\n",cur);
}
int t;
int main()
{
//freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);
scanf("%d",&t);
for(int Case=;Case<=t;Case++)
{
printf("Case #%d: ",Case);
cin>>op;
solve(op);
}
return ;
}

最新文章

  1. css自定义三角形效果
  2. Reactive Extensions介绍
  3. PHP 生成PDF
  4. linux 查找文件的命令
  5. JS数组中every(),filter(),forEach(),map(),some()方法学习笔记!
  6. JMeter学习-006-Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002 解决办法(windows 7)
  7. STM32F0系列MCU中断向量表的重映射
  8. bzoj1055
  9. 深度克隆---js对象引用
  10. dubbo(soa分布式)与cobar(mysql分布式)
  11. 迁移笔记:php缓存技术memcached
  12. poj1543---完美立方(枚举)
  13. 后台运行之BackgroundWorker
  14. Django权限管理测试
  15. trait
  16. nginx----------前端写了一套带有vue路由的的功能。放到nginx配置的目录下以后,刷新会报404未找到。
  17. js 两数组去除重复数值
  18. 【LOJ6053】简单的函数(min_25筛)
  19. 框架中的导航框架 &amp; position定位
  20. Sybase&#183;调用存储过程并返回结果

热门文章

  1. M方法
  2. hive参数配置
  3. 机器学习之numpy库中常用的函数介绍(一)
  4. E. Fish (概率DP)
  5. 移动端效果之Picker
  6. wxPython中基本控件学习
  7. Hibernate操作数据库的回调机制--Callback
  8. commons-pool与commons-pool2连接池(Hadoop连接池)
  9. 吾八哥学Python(六):运算符与表达式
  10. Bootstrap 引用的标准模板