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 |
不知道什么地方错了,hawk师兄可不可以帮看看什么数据的问题#include< iostream.h> #include< string.h > class K { public: int Or_And ; int Y_N ; char ch ; K *left , *right ; K( int a , int b ) { ch = '0' ; Or_And = a ; Y_N = b ; left = NULL ; right = NULL ; } }; char grou[105][105] ; char ch[100][28] ; int x, y ,x0 ,y0 , first ; K *head ; void GoUporDown( int &x , int &y ) { y-- ; if ( grou[x+1][y+1] == '|' ) while( grou[x][y-1] != '-' ) x++ ; if ( grou[x-1][y+1] == '|' ) while( grou[x][y-1] != '-' ) x-- ; } void GoLeft(int LorR , int x , int y , K* p) { int g = 1 , h ; K *node ; while(1) { // cout << x <<" " << y << endl ; // cin >> h ; while( grou[x][y] == '-' ) y-- ; if ( grou[x][y] == '+' ) GoUporDown( x ,y ); if ( grou[x][y] == 'o' ) { g *= -1 ; y-- ; } if ( grou[x][y] == '>' || grou[x][y] == ')') { if ( grou[x][y] == '>' ) h = 1; else h = 2 ; if ( first == 0 ) { first = 1 ; head = new K( h , g ) ; GoLeft( 1 , x-1 , y-3 , head ) ; GoLeft( 2 , x+1 , y-3 , head ) ; return ; } else { node = new K( h , g ) ; if ( LorR == 1 ) p->left = node ; else p->right = node ; GoLeft( 1 , x-1 , y-3 , node ) ; GoLeft( 2 , x+1 , y-3 , node ) ; return ; } } if ( grou[x][y] <= 'Z' && grou[x][y] >= 'A' ) { node = new K( 0 , g ) ; node->ch = grou[x][y] ; if ( first != 0 ) { if ( LorR == 1 ) p->left = node ; else p->right = node ; } else head = node ; return ; } } } int Logi( K* p ,char *pCh ) { int a , b; // cout << p->ch<< " " << p->Or_And << endl; if ( p->ch == '0' ) { a = Logi( p->left , pCh); b = Logi( p->right , pCh); if ( p->Or_And == 1 ) { // cout << ((a||b) -0.5 ) * p->Y_N + 0.5 << endl; return( ( (a||b) -0.5 ) * p->Y_N + 0.5 ) ; } else { // cout << ((a&&b) -0.5 ) * p->Y_N + 0.5 << endl; return( ( (a&&b) -0.5 ) * p->Y_N + 0.5 ) ; } } else { // cout << pCh[p->ch-'A'] << ( pCh[p->ch-'A'] - '0' -0.5 ) * p->Y_N + 0.5 << endl; return ( ( pCh[p->ch-'A'] -'0' -0.5 ) * p->Y_N + 0.5 ) ; } } void main() { while( cin ) { int i , j ,k ; i = 0 ; first = 0 ; cin.getline( grou[i++] , 103 ); while( strcmp(grou[i-1] , "*" )) cin.getline( grou[i++] ,103 ); for( j = 0 ; j < i ; j++ ) { k = 0 ; while( grou[j][k] != '\0' ) { if ( grou[j][k] == '?' ) { x0 = j ; y0 = k ; j = i ; break ; } k++ ; } } x = x0 ; y = y0 ; GoLeft( 0 , x , y-1 ,NULL) ; i = 0 ; cin >> ch[i] ; while( strcmp( ch[i] ,"*" )) { cout << Logi( head , ch[i] ) << endl ; i++ ; cin >> ch[i] ; } cout << endl ; } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator