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 frkstyc at 2005-06-15 21:56:34 on Problem 2106
In Reply To:谁能帮忙看看 贡献了不少WA了 给几个测试数据也行 谢了... Posted by:nestle at 2005-06-15 21:55:44
> #include <iostream>
> #include <cstdio>
> #include <cstring>
> #include <map>
> using namespace std;
> int operater[200];    //1
> int operand[200];    //2
> map <char,int> isp;  //栈内优先数 
> map <char,int> icp;  //栈外优先数 
> char f[2]={'F','V'};
> int top1,top2;
> void init(){
>    isp['(']=1;  isp['&']=5;  isp['|']=3;  isp['!']=6;  isp[')']=8;  
>    icp['(']=8;  icp['&']=4;  icp['|']=2;  icp['!']=7;  icp[')']=1;   
>    return ;
> }
> void cal(char c){
>    int num,left,right;
>    if(c=='!'){
>       num=operand[--top2]=='V'?1:0;
>       operand[top2++]=f[!num];
>    }    
>    else {
>       right=operand[--top2]=='V'?1:0;
>       left=operand[--top2]=='V'?1:0;
>       if(c=='|'){
>          operand[top2++]=f[left||right];
>       }     
>       else if(c=='&'){
>          operand[top2++]=f[left&&right];
>       }    
>    }    
>    return ;
> }    
> int main(){
>    init();
>    int kase=0;
>    char ch;
>    while((ch=getchar())!=EOF){
>       top1=top2=0; 
>       while(1){
>          if(ch=='\n'||ch==EOF)  break;
>          if(ch==' '){
>             ch=getchar();
>             continue;
>          }    
>          else if(ch=='V'||ch=='F'){
>             operand[top2++]=ch;
>             ch=getchar();
>          }    
>          else {
>             if(top1&&icp[ch]<isp[operater[top1-1]]){
>                cal(operater[--top1]);
>             }    
>             else if(top1&&icp[ch]==isp[operater[top1-1]]){
>                --top1;
>                ch=getchar();
>             }    
>             else{
>                operater[top1++]=ch;
>                ch=getchar();
>             }    
>          }    
>       }    
>       if(ch=='\n'){
>          while(top1){
>             cal(operater[--top1]);
>          }    
>          printf("Expression %d: %c\n",++kase,operand[top2-1]);   
>       }    
>       else if(ch==EOF)  break;
>    }    
>    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