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 |
怎么就一路Runtime Error呢,大虾帮我看下#include<iostream> using namespace std; #include<stdlib.h> #include<stdio.h> #include<string.h> typedef char ele; typedef struct Stack { ele data; struct Stack *next; }Stack,*sta; void CreateStack(sta &L) { L=(sta)malloc(sizeof(Stack)); if(L) L->next=NULL; } void push(sta &L,ele e) { Stack *q,*top; top=L; q=(sta)malloc(sizeof(Stack)); if(q) { q->data=e; q->next=top->next; top->next=q; } } char pop(sta &L,ele &e) { Stack *top,*q; top=L; e=top->next->data; q=top->next; top->next=q->next; free(q); return e; } char gettop(sta &L) { Stack *top; top=L; ele e; e=top->next->data; return e; } int pritab(int m,int n) { int a[6][6]; int i,j; for(i=0;i<6;i++) { for(j=0;j<6;j++) { a[i][j]=1; } } a[5][5]=a[3][4]=0; a[0][2]=a[0][3]=a[0][1]=-1; a[1][2]=a[1][3]=-1; a[2][3]=-1; for(i=0;i<4;i++) { a[3][i]=-1; a[5][i]=-1; } return a[m][n]; } int jude(char ch) { int i=0,flag=1; char opr[6]={'(',')','!','|','&','#'}; for(;i<6;i++) if(ch==opr[i]) flag=0; return flag; } int constrast(char ch) { switch(ch) { case '|':return 0; break; case '&':return 1; break; case '!':return 2; break; case '(':return 3;break; case ')':return 4; break; case '#':return 5; break; } } char Compare(char opr,char ch) { int m=0,n=0; char tag; m=constrast(opr); n=constrast(ch); if(pritab(m,n)==1) tag='>'; if(pritab(m,n)==0) tag='='; if(pritab(m,n)==-1) tag='<'; return tag; } char wk(char a,char c,char b) { //if((a=='F'&&b=='F'&&c=='|')||(c=='&'&&a=='F'&&b=='F')||(c=='&'&&a=='V'&&b=='F')||(c=='&'&&a=='F'&&b=='V')) if((a=='F'&&b=='F'&&c=='|')||(c=='&'&&(a=='F'||b=='F'))) return 'F'; else return 'V'; } char wk1(char c,char b) { if(c=='!'&&b=='V') return 'F'; if(c=='!'&&b=='F') return 'V'; } void fun(char inputchar[1000],int len) { int k=0; char ch=' ',theta=' ',a=0,b=0; sta OPRDATA; sta OPTR; CreateStack(OPRDATA); CreateStack(OPTR); push(OPTR,'#'); for(k=0;k<len;) { ch=inputchar[k]; if(ch!='#'||gettop(OPTR)!='#') { int temp; temp=jude(ch); if(temp) { push(OPRDATA,ch); ++k; } else { switch(Compare(gettop(OPTR),ch)) { case '<': push (OPTR,ch); ++k; break; case '=': pop(OPTR,ch); ++k; break; case '>': { if(ch=='!'&&inputchar[k-1]=='!') { push (OPTR,ch); k++; break; } theta=gettop(OPTR); pop(OPTR,theta); pop(OPRDATA,b); if(theta=='!') { push(OPRDATA,wk1(theta,b)); } else { pop(OPRDATA,a); push(OPRDATA,wk(a,theta,b)); } //I=k; break; } } } } else break; } cout<<gettop(OPRDATA)<<endl; } int main() { //freopen("2106.txt","r",stdin); int o=0; char inputchar[1000]={'\0'}; char ch=' '; int len=0,i=0; while(1) { i=0; memset(inputchar,'\0',sizeof(inputchar)); while(ch=getchar(),ch!='\n') { if(ch!=' ') { inputchar[i++]=ch; } } inputchar[i]='#'; len=strlen(inputchar); if(len==1) { break; } cout<<"Expression "<<++o<<": "; fun(inputchar,len); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator