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 ...
随机推荐
- 【dp】 poj 1157
不错的dp入门题 画出dp矩阵 每个dp[i][j]是由“其上”的状态或是“其左上”的状态转化而来,那我们选对角线和上边进行三角dp推导 #include<stdio.h> #incl ...
- pkgmgmt: Comparison between different Linux Systems..
found this page.. already done by precedents.. installation: aptitude install apt-get install yum in ...
- loadrunner基本概念、安装及术语(一)
一.初识loadrunner: LoadRunner,是一种预测系统行为和性能的负载测试工具.通过以模拟上千万用户实施并发负载及实时性能监测的方式来确认和查找问题,LoadRunner能够对整个企业架 ...
- 第三方 XListview 上拉加载、下拉刷新、分页加载和Gson解析
注意:此Demo用的是第三方的Xlistview.jar,需要复制me文件夹到项目中,两个XML布局文件和一张图片 把下面的复制到String中 <string name="xlist ...
- AI 人工智能 探索 (十)
呼叫事件图形结构如下 蓝色代表 警察局 红色代表警察 黄色代表 死亡人 蓝色球代表呼救人 黑色代表 敌人 警察目标是 攻击 黑色人,但 路中 会碰到 黄色人,如果警察有 救人功能 则会先救人去医院再看 ...
- poj 3020 Antenna Placement (最小路径覆盖)
二分图题目 当时看到网上有人的博客写着最小边覆盖,也有人写最小路径覆盖,我就有点方了,斌哥(kuangbin)的博客上只给了代码,没有解释,但是现在我还是明白了,这是个最小路径覆盖(因为我现在还不知道 ...
- 如何参与Hibernate-ORM项目
1.注册 hibernate jira账户,hibernate中的issue和bug都会在此论坛发布 注册地址:https://hibernate.onjira.com 2.创建Hibernate-O ...
- Windows API 之 CreateFile、CreateFileMapping 、MapViewOfFile
CreateFile Creates or opens a file or I/O device. The most commonly used I/O devices are as follows: ...
- Codeforces Round #349 (Div. 2) C. Reberland Linguistics (DP)
C. Reberland Linguistics time limit per test 1 second memory limit per test 256 megabytes input stan ...
- hdu_5213_Lucky(莫队算法+容斥定理)
题目连接:hdu_5213_Lucky 题意:给你n个数,一个K,m个询问,每个询问有l1,r1,l2,r2两个区间,让你选取两个数x,y,x,y的位置为xi,yi,满足l1<=xi<=r ...