| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
这题做的人好少。。。贴个代码吧#include <cstdio>
#include <cstring>
struct node {
int e, c[15];
}p[100000];
int cur, plus;
int bnode(int i) {
char st[25], pa[25] = "1";
int co, j, e;
scanf("%s", st);
p[i].e = 0, memset(p[i].c, 0, sizeof(p[i].c));
switch(st[0]) {
case 'E':
return 0;
case 'O':
scanf("%d", &co);
p[i].e = 0, p[i].c[0] = co;
return 1;
case 'L':
scanf("%s", pa);
case 'B':
while(bnode(j = ++cur)) {
if(p[i].e < p[j].e)
p[i].e = p[j].e;
for(e = 0; e <= p[j].e; e++)
p[i].c[e] += p[j].c[e];
}
if(pa[0] == 'n') {
for(e = p[i].e; e >= 0; e--)
p[i].c[e + 1] = p[i].c[e];
p[i].c[0] = 0;
p[i].e ++;
}
else {
sscanf(pa, "%d", &co);
for(e = p[i].e; e >= 0; e--)
p[i].c[e] *= co;
}
return 1;
}
}
void pterm(int c, int e) {
if(!c && (e || plus)) return;
if(plus) printf("+");
if(c - 1 || !e) printf("%d", c);
if(c - 1 && e) printf("*");
if(e) printf("n");
if(e - 1 && e) printf("^%d", e);
plus = 1;
}
int main() {
int T, cas = 0, e;
scanf("%d", &T);
while(T--) {
printf("Program #%d\nRuntime = ", ++cas);
bnode(cur = 0), plus = 0;
for(e = p[0].e; e >= 0; e--)
pterm(p[0].c[e], e);
printf("\n\n");
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator