若c=b,则之前的C不要求,直到遇到更前面有a=c或a*=c或a+=c时,C的值才要计算
#include<iostream> #include<cstdio> #include<string.h> using namespace std; const int base=10000; const int width=4; const int N=1300; struct bint { int ln,v[N]; bint(int r=0) { for(ln=0;r>0;r/=base) v[ln++]=r%base; } bint operator = (const bint& r) { memcpy(this,&r,(r.ln+1)*sizeof(int)); } }; bool operator < (const bint& a,const bint& b) { int i; if(a.ln!=b.ln) return a.ln<b.ln; for(i=a.ln-1;i>=0&&a.v[i]==b.v[i];i--); return i<0?0:a.v[i]<b.v[i]; } bool operator <= (const bint& a,const bint& b) { return !(b<a); } bint operator + (const bint& a,const bint& b) { bint res; int i,cy=0; for(i=0;i<a.ln||i<b.ln||cy>0;i++) { if(i<a.ln) cy+=a.v[i]; if(i<b.ln) cy+=b.v[i]; res.v[i]=cy%base;cy/=base; } res.ln=i; return res; } bint operator * (const bint& a,const bint& b) { bint res;res.ln=0; if(0==b.ln){ res.v[0]=0;return res; } int i,j,cy; for(i=0;i<a.ln;i++) for(j=cy=0;j<b.ln||cy>0;j++,cy/=base) { if(j<b.ln) cy+=a.v[i]*b.v[j]; if(i+j<res.ln) cy+=res.v[i+j]; if(i+j>=res.ln) res.v[res.ln++]=cy%base; else res.v[i+j]=cy%base; } return res; } void write(const bint& v) { int i; printf("%d",v.ln==0?0:v.v[v.ln-1]); for(i=v.ln-2;i>=0;i--) printf("%04d",v.v[i]); printf("\n"); } char buf[10]; bint b[10]; struct o { int a,b,o;//0:+ 1:* 2:= }o[400000]; bool flag[10],cal[400000]; int main() { for(int i=0;i<10;i++) b[i]=1; int i=0; while(scanf("%s",buf)!=EOF&&buf[0]!='#') { o[i].a=buf[0]-'A'; if(buf[1]=='+') o[i].o=0,o[i].b=buf[3]-'A'; else if(buf[1]=='*') o[i].o=1,o[i].b=buf[3]-'A'; else o[i].o=2,o[i].b=buf[2]-'A'; i++; } for(int j=0;j<10;j++) flag[j]=true; for(int j=i-1;j>=0;j--) { cal[j]=flag[o[j].a]; if(o[j].o==2) flag[o[j].a]=false,flag[o[j].b]=true; } for(int j=0;j<i;j++) { if(cal[j]) { if(o[j].o==0) b[o[j].a]=b[o[j].a]+b[o[j].b]; else if(o[j].o==1) b[o[j].a]=b[o[j].a]*b[o[j].b]; else b[o[j].a]=b[o[j].b]; } } for(int i=0;i<10;i++) write(b[i]); return 0; }
您还没有登录,请您登录后再发表评论
HDU的1250,主要是利用高精度加法,但是代码有点繁琐,效率不是很高
HDU1059的代码
杭电ACMhdu1163
hdu1001解题报告
hdu 1574 passed sorce
HDU的一题........HDU DP动态规
hdu acm 教案 搜索入门 hdu acm 教案 搜索入门
hdu2101AC代码
搜索 dfs 解题代码 hdu1241
hdu acm 教案 动态规划(1) hdu acm 教案 动态规划(1)
hdu 5007 Post Robot 字符串枚举。 暴力一下就可以了。
ACM HDU题目分类,我自己总结的大概只有十来个吧
HDU最全ac代码
hdu 1166线段树代码
hdu动态规划算法集锦
hdu题目分类
hdu-acm源代码(上百题)hdu-acm源代码、hdu-acm源代码hdu-acm源代码
自己做的HDU ACM已经AC的题目
HDU图论题目分类
hdu 1005.比较简单的一道题,有兴趣的可以看看。
相关推荐
HDU的1250,主要是利用高精度加法,但是代码有点繁琐,效率不是很高
HDU1059的代码
杭电ACMhdu1163
hdu1001解题报告
hdu 1574 passed sorce
HDU的一题........HDU DP动态规
hdu acm 教案 搜索入门 hdu acm 教案 搜索入门
hdu2101AC代码
搜索 dfs 解题代码 hdu1241
hdu acm 教案 动态规划(1) hdu acm 教案 动态规划(1)
hdu 5007 Post Robot 字符串枚举。 暴力一下就可以了。
ACM HDU题目分类,我自己总结的大概只有十来个吧
HDU最全ac代码
hdu 1166线段树代码
hdu动态规划算法集锦
hdu题目分类
hdu-acm源代码(上百题)hdu-acm源代码、hdu-acm源代码hdu-acm源代码
自己做的HDU ACM已经AC的题目
HDU图论题目分类
hdu 1005.比较简单的一道题,有兴趣的可以看看。