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

苍天啊,大地啊!谁给我出这口客气,为啥老是WA!!

Posted by xuguangshengqq at 2007-04-13 13:14:27 on Problem 1669
以下是我的代码
我是 按优先级顺序 ~ > & > ^ > |
处理的  
希望牛人给个本程序错误的数据!!
跪求!!!
多谢!!!!! 


#include <iostream.h>
#include <memory.h>
#include<stdio.h>

struct stack{
int top;
char data[300];
};
struct boolStack{
int top;
bool data[300];
};

char a[300];
char d1[300];
char d2[300];

stack ss1,ss2;
boolStack ss3;
bool used[100];
int  idx[100];
bool ever[100];
int n;



int getIndex();
void getHouZhuiShi(int front,int rear);
bool getValue(char *d,int ld);

void main(){
  int i,j,k,ld1,ld2;
  int num;
  int len;
  int index = 0;
  cin>>num;
  for(i=1;i<=num;i++){
	gets(a+1);
    j=1;
	n = 1;
	memset(ever,0,sizeof(ever));
	while(a[j]){
		if(a[j]>='a'&&a[j]<='z'&&!ever[a[j]-'a'+1])
		{
			ever[a[j]-'a'+1] = true;
			idx[a[j]-'a'+1] = n;
			n++;
		}
		j++;
	}
	len = j-1;
	n--;
	index = getIndex();
   getHouZhuiShi(1,index);
   j=1;
   ld1 = ss1.top + 1;
   while(ss1.top>=0)
   {
   d1[j++] = ss1.data[ss1.top--];
   }
   getHouZhuiShi(index+1,len);
   j = 1;
   ld2 = ss1.top+1;
   while(ss1.top>=0)
   {//cout<<"ss1.top = "<<ss1.top<<endl;
   d2[j++] = ss1.data[ss1.top--];
   }
 //  cout<<"d1 = "<<(d1+1)<<endl;
 //  cout<<"d2 = "<<(d2+1)<<endl;
   memset(used,0,sizeof(used));
   //cout<<"memset"<<endl;
   bool b1,b2;
   bool flag = true;
    while(!used[n+1]){
		//for(k=1;k<=n;k++){
		//cout<<used[k]<<",";
		//}cout<<endl;
	b1 = getValue(d1,ld1);
	b2 = getValue(d2,ld2);
//	cout<<"b1 = "<<b1<<",  b2 = "<<b2<<endl;
    if(b1!=b2){
		flag = false;
		break;
	}
	j = 1;
	while(used[j]){used[j] = false;j++;}
	used[j] = true;
  }
    if(flag){
		cout<<"Data set "<<i<<": Equivalent"<<endl;
	}
	else cout<<"Data set "<<i<<": Different"<<endl;

  }
return;
}


bool getValue(char *d,int ld){
int i;
i = 1;
bool a1,a2;
ss3.top = -1;
while(i<=ld){
	//cout<<"d["<<i<<"] = "<<d[i]<<endl;
	if(d[i]>='a'&&d[i]<='z'){
		while(d[i]>='a'&&d[i]<='z'){
		ss3.data[++ss3.top] = used[idx[d[i]-'a'+1]];
		i++;
		}
	continue;
	}
	switch(d[i]){
    case '|':
		a1 = ss3.data[ss3.top--];
		a2 = ss3.data[ss3.top--];
		ss3.data[++ss3.top] = (a1||a2);
     break;
	case '&':
		a1 = ss3.data[ss3.top--];
		a2 = ss3.data[ss3.top--];
		ss3.data[++ss3.top] = (a1&&a2);
     break;	
	case '^':
		a1 = ss3.data[ss3.top--];
		a2 = ss3.data[ss3.top--];
		ss3.data[++ss3.top] = (!a1&&a2||a1&&!a2);
     break;
	 case '~':
		a1 = ss3.data[ss3.top--];
		ss3.data[++ss3.top] = (!a1);
     break;
	}



i++;
}
return ss3.data[0];

return false;
}










void printss1(){
int i;
cout<<"ss1 :  ";
for(i=0;i<=ss1.top;i++){
cout<<ss1.data[i];
}cout<<endl;
}
void printss2(){
int i;
cout<<"ss2 :  ";
for(i=0;i<=ss2.top;i++){
cout<<ss2.data[i];
}cout<<endl;
}





void getHouZhuiShi(int front,int rear){
int i;
//cout<<"front = "<<front<<endl;
//cout<<"rear = "<<rear<<endl;
ss1.top = -1;//符号栈
ss2.top = -1;//数字栈
char ch;
for(i=front;i<=rear;i++){
	switch(a[i]){
	case 'a':
	case 'b':
	case 'c':
	case 'd':
	case 'e':
	case 'f':
	case 'g':
	case 'h':
	case 'i':
	case 'j':
	case 'k':
	case 'l':
	case 'm':
	case 'n':
	case 'o':
	case 'p':
	case 'q':
	case 'r':
	case 's':
	case 't':
	case 'u':
	case 'v':
	case 'w':
	case 'x':
	case 'y':
	case 'z':
		ss2.data[++ss2.top] = a[i];
	break;
	case '|':
		while(ss1.top>=0){
		ch = ss1.data[ss1.top--];
		if(ch == '('){
		ss1.data[++ss1.top] = ch;
		break;
		}
		ss2.data[++ss2.top] = ch;
		}
		ss1.data[++ss1.top] = a[i];
		break;

	case '^':
	 while(ss1.top>=0){
		ch = ss1.data[ss1.top--];
		if(ch == '('||ch=='|'){
		ss1.data[++ss1.top] = ch;
		break;
		}
		ss2.data[++ss2.top] = ch;
		}
		ss1.data[++ss1.top] = a[i];
		break;
    case '&':
        while(ss1.top>=0){
		ch = ss1.data[ss1.top--];
		if(ch == '('||ch=='|'||ch=='&'){
		ss1.data[++ss1.top] = ch;
		break;
		}
		ss2.data[++ss2.top] = ch;
		}
		ss1.data[++ss1.top] = a[i];
		break;
		

			
	case '~':
	 while(ss1.top>=0){
		ch = ss1.data[ss1.top--];
		if(ch == '('||ch=='|'||ch=='&'||ch=='^'||ch=='~'){
		ss1.data[++ss1.top] = ch;
		break;
		}
		ss2.data[++ss2.top] = ch;
		}
		ss1.data[++ss1.top] = a[i];
		break;	
	case '(':
		ss1.data[++ss1.top] = a[i];
		break;
	case ')':
		while(ss1.top>=0){
		ch = ss1.data[ss1.top--];
		if(ch == '(')	break;
	    ss2.data[++ss2.top] = ch;
		}
		break;


    default: break;
	}
//	printss1();
   // printss2();
}
while(ss2.top>=0){
ss1.data[++ss1.top] = ss2.data[ss2.top--];
}
//int top = ss1.top;
//while(top>=0){
//cout<<ss1.data[top--];
//}
//cout<<endl;
}





int getIndex(){//区分两个 式子
bool v=false,p=true;
int i = 1;
while(a[i]){
	//cout<<"v = "<<v<<",  p = "<<p<<endl;
	if(v&&p&&(!(a[i]==' '||a[i]=='|'||a[i]=='&'||a[i]=='^')))
	{
	return (i-1);
	}
	else{
	if(a[i]>='a'&&a[i]<='z')
	{
	v = true;
	}
	else if (a[i] == '~')
	{
	 v = false;
	}
    else if(a[i]=='|'||a[i]=='^'||a[i]=='&')
	{
	v = false;
	}
	else if(a[i]=='(')
	{
	v = true;
	p = false;
	}
	else if(a[i]==')'){
	p = true;
	}
	}
	i++;
}
return -1;
}









/*
 */

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