1014 - #include<cstdio>

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: #include<cstdio> #include<cstring> #include<cstdlib> using namespace std; /* + * ^ () */ // Care for ^, for we can only split a^b^c into two different parts, a b^c, instead of three parts. enum { SIZ = 1008, }; char buffer[SIZ]; typedef struct { int childnum; int child[100]; int start; int end; }Node; Node tree[SIZ]; int num; int stack[100]; int pos; void parse(int,int,int); // If there is +, then we split it with + int checkfor_add(int node){ int deep = 0; int i, last = tree[node].start; for(i=tree[node].start; i<tree[node].end;i++){ if(buffer[i] =='('){ deep ++; } else if(buffer[i] ==')'){ deep --; } else if(buffer[i] =='+' && deep == 0){ if(i == last ){ last = i+1; continue; } tree[node].child[ tree[node].childnum ++ ] = num; parse(num++,last,i); last = i+1; } } if(last != tree[node].start){ tree[node].child[tree[node].childnum++] = num; parse(num++,last,tree[node].end); return 1; } return 0; } // Process for multiply, including * and ()() int checkfor_mult(int node){ int deep = 0; int i, last = tree[node].start; for(i=tree[node].start; i<tree[node].end;i++){for(i=tree[node]....
View Full Document

Page1 / 4

1014 - #include<cstdio>

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online