简单模拟题。一个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的更多相关文章

  1. ZOJ - 3930 Dice Notation 【模拟】

    题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3930 题意 给出一串字符串 如果是 '+' '-' '*' '/ ...

  2. Dice Notation(模拟)

    Dice Notation Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit  ...

  3. zoj 3829 Known Notation

    作者:jostree 转载请说明出处 http://www.cnblogs.com/jostree/p/4020792.html 题目链接: zoj 3829 Known Notation 使用贪心+ ...

  4. 贪心+模拟 ZOJ 3829 Known Notation

    题目传送门 /* 题意:一串字符串,问要最少操作数使得成为合法的后缀表达式 贪心+模拟:数字个数 >= *个数+1 所以若数字少了先补上在前面,然后把不合法的*和最后的数字交换,记录次数 岛娘的 ...

  5. ZOJ 3829 Known Notation 贪心

    Known Notation Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showPro ...

  6. ZOJ 3829 Known Notation (2014牡丹江H称号)

    主题链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=5383 Known Notation Time Limit: 2 S ...

  7. ZOJ 3829 Known Notation 乱搞

    乱搞: 1.数字的个数要比*的个数多一个,假设数字不足须要先把数字补满 2.最优的结构应该是数字都在左边,*都在右边 3.从左往右扫一遍,遇到数字+1,遇到*-1,假设当前值<1则把这个*和最后 ...

  8. ZOJ 3826 Hierarchical Notation 模拟

    模拟: 语法的分析 hash一切Key建设规划,对于记录在几个地点的每个节点原始的字符串开始输出. . .. 对每一个询问沿图走就能够了. .. . Hierarchical Notation Tim ...

  9. zoj 3829 Known Notation(2014在牡丹江区域赛k称号)

    Known Notation Time Limit: 2 Seconds      Memory Limit: 131072 KB Do you know reverse Polish notatio ...

随机推荐

  1. Socks

    Socks time limit per test 2 seconds memory limit per test 256 megabytes input standard input output ...

  2. ios中点语法、property跟synthesize用法

    一:OC中得点语法 1> 点语法的基本使用: ·使用 对象.成员变量   可以实现设置成员变量值,和获取成员变量的值   2> 点语法的本质 (点语法是Xcode编译器自己帮我们完成的一个 ...

  3. 使用jquery的js的页面实现例子

    var validate;var nodeId="";var modifyappId=""; addExportTaskURL = ctx + "/x ...

  4. 多线程进阶之并发工具类:CountDownLatch、CyclicBarrier

    并发工具类在java.util.concurrent包下.常用的有CountDownLatch.CyclicBarrier,用它们可以控制并发流程. 1.CountDownLatch探究: 主要用到其 ...

  5. HDU1548:A strange lift

    A strange lift Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Tota ...

  6. js html 交互监听事件学习

    事件处理程序(handler): HTML事件处理程序: <input type="button" value="Click Here" onclick= ...

  7. CodeForces 678A Johny Likes Numbers

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...

  8. git 管理多个私钥

    .ssh/config文件: host imspring hostname 182.92.153.2 IdentityFile ~/.ssh/id_rsa port 22

  9. jq中的css-Dom

    1,height() ,width() 此方法用来获取匹配元素的高和宽的值,如果括号内有值,则是修改匹配元素的值, 2.offset() 此方法的作用是获取元素在当前视窗的相对偏移,其中返回的对象包含 ...

  10. decimal 和 numeric (Transact-SQL)

    decimal(18,0)18是定点精度,0是小数位数.decimal(a,b)a指定指定小数点左边和右边可以存储的十进制数字的最大个数,最大精度38.b指定小数点右边可以存储的十进制数字的最大个数. ...