ZOJ 3930 Dice Notation
简单模拟题。一个int写成了char,搞了4个多小时。真垃圾。。
#include<stdio.h>
#include<string.h> char tmp[+],s[+];
char ans[+];
char u[+];
int g;
int T,len,f; void init()
{
memset(tmp,,sizeof tmp);
memset(ans,,sizeof ans);
f=;
memset(s,,sizeof s);
len=;
} void c()
{
for(int i=; tmp[i]; i++)
if(
tmp[i]=='d'
||tmp[i]=='+'||tmp[i]=='-'||tmp[i]=='*'||tmp[i]=='/'
||tmp[i]=='('||tmp[i]==')'
||(tmp[i]>=''&&tmp[i]<='')
)
s[len++]=tmp[i];
} void work()
{
int pre=;
int pos1,pos2;
for(int i=; s[i]; i++)
{
if(s[i]=='d')
{
pos1=i,pos2=i;
for(int j=i+; s[j]; j++)
{
if(s[j]>=''&&s[j]<='') pos2=j;
else break;
} for(int j=i-; j>=; j--)
{
if(s[j]>=''&&s[j]<='') pos1=j;
else break;
} int a=;
for(int j=pos1; j<=i-; j++) a=a*+s[j]-''; for(int j=pre; j<pos1; j++) ans[f++]=s[j];
pre=pos2+; memset(u,,sizeof u);
g=;
u[g++]='[';
for(int j=i; j<=pos2; j++) u[g++]=s[j];
u[g++]=']'; if(a==) a=;
if(a!=) ans[f++]='(';
for(int k=; u[k]; k++) ans[f++]=u[k];
for(int j=; j<=a-; j++)
{
ans[f++]='+';
for(int k=; u[k]; k++) ans[f++]=u[k];
}
if(a!=) ans[f++]=')'; }
}
for(int j=pre; s[j]; j++) ans[f++]=s[j];
} void print()
{
for(int i=; ans[i]; i++)
{
if(ans[i]=='+'||ans[i]=='-'||ans[i]=='*'||ans[i]=='/') printf(" %c ",ans[i]);
else printf("%c",ans[i]);
}
printf(" = [Result]\n");
} int main()
{
scanf("%d",&T);
getchar();
while(T--)
{
init();
gets(tmp);
c();
work();
print();
}
return ;
}
ZOJ 3930 Dice Notation的更多相关文章
- ZOJ - 3930 Dice Notation 【模拟】
题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3930 题意 给出一串字符串 如果是 '+' '-' '*' '/ ...
- Dice Notation(模拟)
Dice Notation Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit ...
- zoj 3829 Known Notation
作者:jostree 转载请说明出处 http://www.cnblogs.com/jostree/p/4020792.html 题目链接: zoj 3829 Known Notation 使用贪心+ ...
- 贪心+模拟 ZOJ 3829 Known Notation
题目传送门 /* 题意:一串字符串,问要最少操作数使得成为合法的后缀表达式 贪心+模拟:数字个数 >= *个数+1 所以若数字少了先补上在前面,然后把不合法的*和最后的数字交换,记录次数 岛娘的 ...
- ZOJ 3829 Known Notation 贪心
Known Notation Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showPro ...
- ZOJ 3829 Known Notation (2014牡丹江H称号)
主题链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=5383 Known Notation Time Limit: 2 S ...
- ZOJ 3829 Known Notation 乱搞
乱搞: 1.数字的个数要比*的个数多一个,假设数字不足须要先把数字补满 2.最优的结构应该是数字都在左边,*都在右边 3.从左往右扫一遍,遇到数字+1,遇到*-1,假设当前值<1则把这个*和最后 ...
- ZOJ 3826 Hierarchical Notation 模拟
模拟: 语法的分析 hash一切Key建设规划,对于记录在几个地点的每个节点原始的字符串开始输出. . .. 对每一个询问沿图走就能够了. .. . Hierarchical Notation Tim ...
- zoj 3829 Known Notation(2014在牡丹江区域赛k称号)
Known Notation Time Limit: 2 Seconds Memory Limit: 131072 KB Do you know reverse Polish notatio ...
随机推荐
- Hibernate 系列教程17-查询缓存
在二级缓存配置成功的基础上进行查询缓存配置 Product public class Product { private Long id; private String name; Product.h ...
- 求N以内与N互质的数的和
题目连接 /* 求所有小于N且与N不互质的数的和. 若:gcd(n,m)=1,那么gcd(n,n-m)=1; sum(n)=phi(n)*n/2; //sum(n)为小于n的所有与n互质的数的和 // ...
- php 个推的例子
个推 http://docs.getui.com/server/php/start/ <?php /** * Created by PhpStorm. * User: xiaochao * ...
- 视频 -> 帧 浅析
原创:转载请注明出处 关于帧率 首先以下几个概念必须弄清楚 1.一个帧就是一个画面 2.视频有无数个帧组成 3.表达时间的量 CMTime 的定义: typedef struct { CMTimeV ...
- openwrt+ndp+ndppd+radvd+dhcpv6,ipv6穿透配置指南
要用ipv6首先你的openwrt路由内核必须已经支持ipv6,且能安装相关软件! 首先说说最简单的ndp手工ipv6穿透,很简单,看代码详解: 环境: wan口 eth1 lan口 br-lan w ...
- AI 人工智能 探索 (七)
我简单画了一幅图,来讲下 ai 中的设计模式.图形中的这些人物,我想大家都能看的明白. 当 盗贼出现,人们发现了他们,就 呼叫 主类,然后主类再 通知 下面对应的管理局,然后管理局再 分配人手过去 ...
- HDU 4460 Friend Chains(map + spfa)
Friend Chains Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total ...
- action参数绑定
thinkPHP支持操作方法的参数绑定功能 action参数通过直接绑定URL中的变量作为操作方法的参数,可以简化方法的定义甚至路由的简析. 原理是把URL的中参数(不包括模块,控制器和操作名)和控制 ...
- Git学习 -- 自定义Git
忽略特殊文件 在工作区创建.gitignore文件,编写内容 # Windows: Thumbs.db ehthumbs.db Desktop.ini # Python: 忽略Python编译产生的. ...
- Python里如何实现C中switch...case的功能
python没有switch case 不过可以通过建立字典实现类似的功能 例子:根据输入的年月日,判断是该年中的第几天 y = int(input('请输入年:')) m = int(input(' ...