Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

大侠看看啊,哪里错了啊?

Posted by ArXoR at 2005-01-03 23:01:03 on Problem 2106
#include "stdio.h"
#define MAX 1000

char p[MAX],t[MAX],r,l,c;
int pi,ti,cou;

void insert(void){
	if (t[--ti]=='!'){
		l=p[--pi];
		p[pi++]=((l=='F')?'V':'F');
	}
	else {
		r=p[--pi];
		l=p[--pi];
		if (t[ti]=='|')
			p[pi++]=(r=='F' && l=='F')?'F':'V';
		else p[pi++]=(r=='V' && l=='V')?'V':'F';
	}
}

int main(){
	for (c=getchar(),cou=1;c!=EOF;c=getchar(),cou++){
    	for (ti=0,pi=0;c!='\n';c=getchar()){
    		switch (c){
      		case ' ':	continue;
    		case 'F':
    		case 'V':	p[pi++]=c;
            			continue;
    		case '(':	t[ti++]=c;
           				continue;
			case '!':	if (ti==0 || t[ti-1]!='!') t[ti++]=c;
         				else ti--;
   						continue;
			case ')':	while(t[ti-1]!='(') insert();
       					ti--;
    					continue;
    		case '|':
      		case '&':	if (ti==0){
    						t[ti++]=c;
    						continue;
  						}
    					if (t[ti-1]!='(' && c>t[ti-1]){
    						insert();
    						t[ti++]=c;
   						}
   						else t[ti++]=c;
   						continue;
    		}
    	}
    	while(ti>0) insert();
	    printf("Expression %d: %c\n",cou,p[0]);
	}
	return 0;
}


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator