简单模拟题。一个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. Java利用POI生成Excel强制换行

    前一段时间在做一个学校排课系统时,有一个地方需要利用把课程表生成excel汇出给客户,由于之前用excel都只是简单的应用,在单元格里都是用自动换行,而这次可能需要用到手动强制换行. 于是我在网上找了 ...

  2. php moungoDB

    moungoDB 语法 SQL查询语句 Mongo查询语句 CREATE TABLE USERS (a Number, b Number) 隐式的创建,或 MongoDB::createCollect ...

  3. pkgmgmt: Comparison between different Linux Systems..

    found this page.. already done by precedents.. installation: aptitude install apt-get install yum in ...

  4. Notes over compiling..

    When compiling VIM on windows, using nmake may be a better choice.. Because so far my attempts to co ...

  5. HDU - 1205 I NEED A OFFER!

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1203 题意: 该题要求得到一份offer的最大概率,在例子中的0.44 = 1-(1-0.2)*(1- ...

  6. 仿照微信的界面,即ViewPager+Fragment的结合使用

    主布局文件: android:drawableTop="@drawable/weixin_bg"用的是状态选择器,所以要写4个状态选择器,图片的 <RelativeLayou ...

  7. double类型之四舍五入

    题目: A - Tutor Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%I64d & %I64u Submi ...

  8. webView进度条

    self.progress = [[NJKWebViewProgress alloc] init]; self.webView.delegate = self.progress; __weak typ ...

  9. BroadcastReceiver的两种注册方式之------静态注册

    activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&qu ...

  10. Windows环境下使用VS2005编译OpenSSL

    如何Windows环境下,使用VS2005编译OpenSSL,虽然这个问题在Baidu.Google上一堆,但安装中还是遇到些问题,在这里 记录下来希望能帮助大家不要在走弯路.注:我是在WinXP S ...