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<iostream> #include<string> using namespace std; char ch; char temp_str[500]; char str[500]; int k; char Getch() { return str[k++]; } void Putch() { k--; } bool expression(void); bool factor(void) { bool re; ch=Getch(); switch(ch) { case 'V': re=true; break; case 'F': re=false; break; case '(': re=expression(); break; case '!': ch=Getch(); if(ch=='(') { Putch(); re=expression(); Putch(); re=!re; } else { Putch(); re=factor(); Putch(); re=!re; } break; default: break; } ch=Getch(); return re; } bool term(void) { bool re=factor(); while(true) { switch(ch) { case '&': re = re & factor(); break; default: return re; } } } bool expression(void) { bool re=term(); while(true) { switch(ch) { case '|': re =re | term(); break; default: return re; } } } int main(void) { int i,j,t; t=1; while(gets(temp_str)!=NULL) { j=0; for(i=0;temp_str[i]!='\0';i++) { if(temp_str[i]!=' ') str[j++]=temp_str[i]; } str[j]='='; // 结束标志 str[j+1]='\0'; // puts(str); k=0; printf("Expression %d: ",t); if(expression()) printf("V\n"); else printf("F\n"); t++; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator