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 ...
随机推荐
- 用GeneratedKeyHolder获得新建数据主键值
public User createUser(final User user) { final String sql = "insert into sys_users(username, p ...
- position的absolute与fixed共同点与不同点
这个问题面试被问到过~~ A:共同点: 1.改变行内元素的呈现方式,display被置为block: 2.让元素脱离普通流,不占据空间: 3.默认会覆盖到非定位元素上 B不同点: absolute ...
- checking for known struct flock definition... configure: error: Don't know how to define struct flock on this system, set --enable-opcache=
在对php进行安装的过程中出现如下错误: 1.报错信息: 1 checking for known struct flock definition... configure: error: Don't ...
- 【转】VC6.0打开或者添加工程文件崩溃的解决方法
很多学习编程的同学都遇到这样的问题,在Windows操作系统下使用Visual C++ 6.0编程时,如果点击菜单中的[打开]或者[添加],或者按快捷键,都会弹出下图的对话框,出现程序崩溃并退出的情况 ...
- 利用apache组件实现文件上传
实现文件上传需要引入: commons-fileupload-1.3.2.jar commons-io-2.5.jar commons-logging-1.2.jar <!DOCTYPE htm ...
- Android接收wifi路由器发送过来的一组字节数据
1.字节数组转换为字符串 byte[] byBuffer = new byte[20];... ...String strRead = new String(byBuffer);strRead = S ...
- 转:Loadrunner打开https报错“Internet…
Loadrunner 录制htpps 协议通过IE打开页面,报错“Internet Explorer cannot display the webpage”. 但是直接打开IE不通过 loadrunn ...
- material design 的android开源代码整理
material design 的android开源代码整理 1 android (material design 效果的代码库) 地址请点击:MaterialDesignLibrary 效果: 2 ...
- ZOJ 2866 Overstaffed Company
树状数组 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
- ping命令使用技巧(一次Ping多个地址)
打开windows 命令行 窗口, 在命令行输入以下命令: for /l %i in (1,1,255) do ping -n 1 -w 60 192.168.0.%i | find " ...