int main() { char line[MAXLINE], exp[MAXLINE]; int vals[LEN]; bool used[LEN]; int i, len, res; FILE *fp = stdin; while ((len = getline(line, exp, fp)) > 0) { init(vals, used); pre_post(exp, vals, 2, len, -1); res = evaluate(exp, used, vals); pre_post(exp, vals, 0, len - 2, 1); printf("Expression: %s\n", line); printf(" value = %i\n", res); for (i = 0; i < LEN; i++) { if (used[i]) { printf(" %c = %i\n", (i + DIFF), vals[i]); } } } fclose(fp); return 0; }
int main() { struct node *END; int A,B; int c1,c2; //adjaceny graph struct node *adj[MAX_VERT+5]; struct node *t; struct order *values; int i,j; int *visited; int NV,NE; int ncases; scanf("%d",&ncases); while(ncases) { scanf("%d %d",&NV,&NE); END=(struct node*)malloc(sizeof(*END)); END->next=END; //points each node to the END node for(i=0;i<=NV;i++) { adj[i]=END; } for(i=0;i<NE;i++) { scanf("%d %d",&A,&B); c1=A;c2=B; t=(struct node*)malloc(sizeof(*t)); t->V=c2;t->next=adj[c1];adj[c1]=t; } // print_adj(adj,NV); values=pre_post(adj,NV); // for(i=1;i<=NV;i++) { // printf("%2d ",i); // } // printf("\n"); // for(i=1;i<=NV;i++) { // printf("%2d ",values[i].pre); // } // printf("\n"); // for(i=1;i<=NV;i++) { // printf("%2d ",values[i].post); // } // printf("\n"); // printf("Checking cyclic\n"); if(isAcyclic(adj,values,NV)) { printf("1 "); } else { printf("-1 "); } // printf("\n"); ncases--; } printf("\n"); return 0; }